In-depth analysis of Python Web applications

Source: Internet
Author: User

This function will be made public through Python Web applications. First, you need to select the Python Web application platform to use, which may be more difficult than writing an application! Because they are very easy to write in Python, a large number of platforms are available.

Alternatively, if you are interested in Ruby on Rails, you may need to consider TurboGears or Django-Python's own top-down Application Builder. TurboGears also supports easily including AJAX in applications. Now we will select a very simple framework, CherryPy. Download it here.

First, modify compareInitOra. py as follows) to create an html () function to return the string containing the required text and tags. Then, you only need to write seven lines of code to publish the function as a Web application.

 
 
  1. import readInitOra, cx_Oracledef readLiveParams(instance):
  2. liveParams = {}orcl = cx_Oracle.connect('scott/tiger@' + instance)curs = orcl.cursor()curs.execute('SELECT name, 
  3. value FROM V$PARAMETER')row = curs.fetchone()while row:(param, val) = (row[0],
  4.  row[1])liveParams[param.upper()] = valrow = curs.
  5. fetchone()return liveParamsfileName = 'init_orcl.ora'def html(initOraFile, instance):
  6. result = ""fileParams = readInitOra.read(initOraFile)liveParams = readLiveParams(instance)for (param, val) 
  7. in fileParams.items():liveVal = liveParams.get(param)if 
  8. liveVal == val:result += "<font color='green'>%s</font><br>\n" % 
  9. (val)elseresult += "<font color='red'>%s (file) %s (live)</font></br>\n" %
  10.  (val, liveVal)return resultimport cherrypyclass WebApp:def index(self, 
  11. initOraFile='init.ora', instance='orcl'):return html(initOraFile, instance
  12. )index.exposed = Truecherrypy.root = WebApp()cherrypy.server.start() 

When running the script, it starts to work on port 8080 in the form of a Python Web Application Server by default. Conclusion We sincerely hope that Python's ease of use, concise lines, and readable lines will interest you. You do not know the powerful functions of Python.

Its functions include concise Exception Handling, unit testing, object-oriented, practical programming, GUI toolkit, Web framework, XML, and Web Services-almost any operation can be performed by programmers. As your work becomes more advanced, you do not have to "transition" to other languages.

In this way, you can easily rewrite the script code as needed, rather than re-compile the dynamic link library of the link binary. The powerful functions of Python are sufficient, but some specific functions of the operating system need to be implemented using C ++, which is then called by Python. Therefore, we need:

1. Embed Python into the C ++ application, call the Python function in the C ++ program, and obtain the value of the variable;
2. Compile the extension module (Dynamic Link Library) for Python using C ++, and call the extension function developed by C ++ In the Python program.

Python Web applications have the most abundant and powerful class libraries in the scripting language, which is sufficient to support most daily applications. Its name comes from a comedy. Perhaps those who initially designed the Language Python did not expect that today Python will be widely used in industry and scientific research.

Eric Raymond, a famous free software author, listed Python as one of the four programming languages that hackers should learn in his article "How To Be a hacker, we recommend that you start learning programming from Python.

This is indeed a pertinent suggestion. Python is one of the best choices for programming learners who have never learned programming or are not computer professional.

  1. How to embed Python into C ++ applications?
  2. In-depth discussion of Ruby and Python syntax comparison
  3. Introduction to Python
  4. Python Learning Experience: version, IDE selection and encoding solution
  5. Analysis of Python GIL and thread security

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.