Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python-script CGI, features, application, development environment

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

CGI

CGI is currently maintained by NCSA. NCSA defines CGI as follows:

CGI (Common Gateway Interface), a universal gateway interface, is a program that runs on a server, such as a HTTP server, and provides an interface with client HTML pages.

CGI programs can be Python scripts, Perl scripts, Shell scripts, C or C++ programs, etc.

Server

Before you do CGI programming, make sure your Web server supports CGI and is configured with CGI handlers.

All HTTP server execution CGI programs are saved in a preconfigured directory. This directory is called the CGI directory, and by convention, it is named the / var/www/cgi-bin directory.

CGI files have a .cgi extension, and python can also use a .py extension.

By default, the Linux server is configured to run / var/www in the cgi-bin directory.

If you want to specify another directory to run the CGI script in, you can modify the httpd.conf configuration file as follows:

/ 1 、 / 2 、 Allow Override None

/ 3 、 Options ExecCGI

/ 4 、 Order allow,deny

/ 5, Allow from all/6, / 7, / 8, Options All/9, Program

Use Python to create the first CGI program, the file name is hello.py, the file is located in the / var/www/cgi-bin directory, the content is as follows, and the permission to modify the file is 755:

1 、 #! / usr/bin/env python

2. Print ("Content-type:text/html\ r\ n\ r\ n")

3. Print (") print (")

4. Print (") 5, print (") 6, print (")

7. Print ("")

8. Print ("Hello World! This is my first CGI program")

9. Print ("")

10. Print ("")

The results of the above programs are displayed in the browser as follows:

1 、 Hello World! This is my first CGI program

The hello.py script for this is a simple Python script. The first output of the script "Content-type:text/html\ r\ n\ r\ n" is sent to the browser and tells the browser that the content type displayed is "text/html".

Environment variable

All CGI programs receive the following environment variables, which play an important role in CGI programs:

The following is a simple CGI script that outputs the environment variables of CGI:

(1) the advantages of os3,print import os3,print "Content-type:text/html\ r\ n\ r\ n\ n\ n5 for param in os.environ.keys (): 6 20s:%s"% (param,os.environ [param]))

Simple: Python is a language that represents the idea of simplism. Reading a good Python program is like reading English. It enables you to focus on solving problems rather than understanding the language itself.

Easy to learn: Python is extremely easy to use because Python has extremely simple documentation.

Speed: the bottom layer of Python is written in C, and many standard libraries and third-party libraries are also written in C, which runs very fast.

Free, open source: Python is one of the FLOSS (free / open source software). Users are free to publish a copy of the software, read its source code, make changes to it, and use part of it in new free software. FLOSS is based on the concept of sharing knowledge by a group.

High-level language: when writing programs in Python, you don't have to consider low-level details such as how to manage the memory your program uses.

Portability: because of its open source nature, Python has been ported to many platforms (modified to work on different platforms). These platforms include Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, z/OS, Palm OS, QNX, VMS, Psion, Acom RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE, PocketPC, Symbian and Google's Android platform based on linux.

Explanation: a program written in a compiled language such as C or C++ can be converted from a source file (i.e. C or C++) to a language used by your computer (binaries, i.e. 0 and 1). This process is done through the compiler and different tags and options.

When running the program, the link / reloader software copies your program from the hard drive to memory and runs it. Programs written in Python do not need to be compiled into binary code. You can run the program directly from the source code.

Inside the computer, the Python interpreter converts the source code into an intermediate form called bytecode, which is then translated into the machine language used by the computer and run. This makes it easier to use Python. It also makes Python programs easier to port.

Object oriented: Python supports both process oriented programming and object oriented programming. In a "process-oriented" language, programs are built from procedures or simply functions that are reusable code. In an "object-oriented" language, programs are built from objects that are a combination of data and functions.

Extensibility: if you need a piece of critical code to run faster or want some algorithms to be private, you can write some programs in C or C++, and then use them in Python programs.

Embeddability: you can embed Python into the CumberCraft + program to provide scripting functionality to program users.

Rich libraries: the Python standard library is really huge. It can help with a variety of tasks, including regular expressions, document generation, unit testing, threading, databases, web browsers, CGI, FTP, e-mail, XML, XML-RPC, HTML, WAV files, password systems, GUI (graphical user interface), Tk, and other system-related operations. This is called Python's "full-featured" concept. In addition to the standard libraries, there are many other high-quality libraries, such as wxPython, Twisted, Python image libraries, and so on.

Canonical code: Python uses forced indentation to make the code readable. Programs written in Python do not need to be compiled into binary code.

Shortcoming

Single-line statements and command-line output problems: most of the time, programs cannot be written on a single line, such as import sys;for I in sys.path:print I. While perl and awk do not have this restriction, it is more convenient to complete a simple program under shell, and there is no need to write the program to a .py file like Python.

Unique grammar

This may not be called limitation, but it still brings confusion to many beginners in the way it distinguishes sentence relations by indentation. Even experienced Python programmers can fall into a trap. The most common situation is that the mixing of tab and spaces can lead to errors, which are indistinguishable to the naked eye.

Slow speed: compared with C and C++ here.

Application

System programming: provides API (Application Programming Interface Application programming Interface), which is convenient for system maintenance and management. It is one of the iconic languages under Linux and is an ideal programming tool for many system administrators.

Graphics processing: supported by PIL, Tkinter and other graphics libraries, it is convenient for graphics processing.

Mathematical processing: the NumPy extension provides a large number of interfaces with many standard math libraries.

Text processing: the re module provided by python supports regular expressions as well as SGML,XML analysis module. Many programmers use python to develop XML programs.

Database programming: programmers can communicate with Microsoft SQL Server,Oracle,Sybase,DB2,MySQL, SQLite and other databases through modules that follow the Python DB-API (database application programming interface) specification. Python comes with a Gadfly module that provides a complete SQL environment.

Network programming: provide a wealth of modules to support sockets programming, can easily and quickly develop distributed applications. Many large-scale software development programs such as Zope,Mnet and BitTorrent. It is widely used by Google.

Web programming: an application development language that supports the latest XML technology.

Multimedia applications: the PyOpenGL module of Python encapsulates the "OpenGL Application programming Interface" and can process 2D and 3D images. The PyGame module can be used to write game software.

Pymo engine: PYMO, whose full name is python memories off, is an AVG game engine running on Symbian S60V3 Symbian S60V5, Symbian3, Android system. It is named PYMO because it is based on the python2.0 platform and is suitable for creating memories off-style AVG games.

* programming: python has a hack library with built-in functions you are familiar with or unfamiliar with, but lacks a sense of accomplishment.

Write simple crawlers with Python

First of all, you need to get the corresponding HTML source code through the Module of urllib2.

1Dome import urllib2 # call urllib2

2 http://www.baidu.com/s?wd=cloga' # assign the URL to the right of the equal sign to url

3 read html urllib2.urlopen (url). The action followed by the random name equal sign is to open the source code page and read

4 print html # print

You can see that the information for url is stored in the span tag, and you can use regular expressions to get the information from it.

Friends who need to know more about the technical issues of Python can follow.

Would like to know more about mingli.com

Please add the ball if you need it: 2042849237

Development environment

● IDLE:Python built-in IDE (provided with python installation package)

● PyCharm: see Baidu encyclopedia PyCharm, developed by the famous JetBrains company, with a complete set of tools that can help users improve their efficiency when developing in Python language, such as debugging, syntax highlighting, Project management, code jumping, smart tips, automatic completion, unit testing, version control. In addition, the IDE provides some advanced features to support professional Web development under the Django framework.

● Komodo and Komodo Edit: the latter is a free simplified version of the former

● Spyder: install the advanced IDE that comes with Anaconda

This IDE is provided by ● PythonWin:ActivePython or pywin32, and is only applicable to Windows

● SPE (Stani's Python Editor): free software with more features, based on wxPython

● Ulipad: full-featured free software, based on wxPython;, the writer is a Chinese Python master limodou

● WingIDE: probably the most versatile IDE, but not free software (educational and open source users can apply for free key)

● Eric: PyQt-based free software, powerful. Full name: The Eric Python IDE

● DrPython

● PyScripter: lightweight open source Python IDE developed using Delphi, with support for Python2.6 and 3.0.

● PyPE: an open source cross-platform PythonIDE.

● bpython: a lightweight Python interpreter developed using the curses library under a Unix-like operating system. Syntax prompt function.

● eclipse + pydev plug-in: easy to debug programs

● emacs: comes with python support, automatic completion, refactor and other functions need plug-in support

● Vim: the latest version 7.3 can be compiled with python support to provide automatic prompt support for python code

● Visual Studio 2003 + VisualPython: Windows only, maintenance stopped, poor functionality

● SlickEdit

● Visual Studio 2010 + Python Tools for Visual Studio

● TextMate

● Netbeans IDE

● Sublime

● ipython

In addition, general programmer text editor software such as Notepad++, EditPlus, UltraEdit can also provide some support for Python code editing, such as automatic code coloring, comment shortcuts, etc., but whether it is up to the level of the integrated development environment remains to be evaluated.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report