"Python database GUI CGI Programming"

Source: Internet
Author: User

This address: http://www.cnblogs.com/aiweixiao/p/8390417.html

Original address

Click to follow the public number Wenyuqinghuai

1. Write in front

Last time, we introduced the introduction to Python, and today we'll cover Python's database, GUI, CGI programming, and Python 2.x and Python 3.x differences.

2. Connect to the database

The Python standard database interface for Python db-api,mysqldb is the interface for the Python link MySQL database. When used, the MYSQLDB module must be installed, otherwise it will be reported that the module can not be found.

Installing the MYSQLDB module under 2.1 Linux

Use package installation to wget http://sourceforge.net/projects/mysql-python/files/latest/download

$ tar xfz mysql-python-1.2.3.tar.gz

$ CD mysql-python-1.2.3

$whereis mysql_config mysql_config:/usr/bin/mysql_config

$ vim site.cfg Modify Mysql_config as the path to the MySQL configuration file/usr/bin/mysql_config

Also to modify Threadsafe = False

$ python setup.py Build

$ sudo python setup.py install

Installing the MYSQLDB module under 2.2 mac

Install PIP using the easy_install pip command

$ easy_install pip


mac install Pip

$ pip Install Mysql-python


PIP installation Mysql-python

2.3 Querying the database

Code on GitHub Source address: HTTP://T.CN/RQJCVFL


manipulating Databases


the output effect of the database

3. GUI Programming

Python provides a library of multiple graphical development interfaces, where Tkinter is the standard GUI library for Python. Python uses Tkinter to quickly create GUI applications.

Code on GitHub Source address: HTTP://T.CN/RQJCVFL


GUI programming for Python


the effect of GUI under Mac system4. CGI Programming

1) Python's cgihttpserver is generally installed with Python, the following command can be started, in order to facilitate the organization of the directory, it is recommended to first create a directory, such as the Web, and then run the following command.

Nohup python-m cgihttpserver 8088 &


schematic diagram

2) static file code address: Http://t.cn/R8wMYHr


front-end HTML code

Access Address: http://localhost:8088/


Front end Diagram

3) The address submitted to the backend is http://localhost:8088/cgi-bin/c_area.sh


Back-end shell code

Back-end shell script address: http://t.cn/R8wMmMn


After submission, the results are calculated as 5. Python 2.x differs from Python 3.x

5.1 Not compatible

3??. of Python Version 0, often referred to as Python 3000, or simply py3k. This is a large upgrade relative to earlier versions of Python.

In order not to take in too much of a burden, Python 3.0 did not consider downward compatibility when designing.

Many of the programs designed for early Python versions are not performing properly on Python 3.0.

To take care of the existing program, Python 2.6, as a transitional version, basically uses the syntax and library of Python 2.x, taking into account the migration to Python 3.0, allowing the use of some of the syntax and functions of Python 3.0.

5.2 A picture wins thousand words


the difference between Python2 and Python3

You can upgrade your own version of Python, it is recommended to adopt Python3 directly, after all it is a trend. Using the 2to3 tool is also a good choice.

6. Written in the last

This article simply accepted the Python database link, GUI, Cui's simple programming, finally introduced briefly the difference between Python2 and Python3, welcome everybody to exchange.


a promising Python

"Python database GUI CGI Programming"

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.