Use python as the development script in IE

Source: Internet
Author: User

Use python as the development script in IE

Currently, client scripting languages supported by IE are commonly VBScript and Javascript. These two scripting languages can basically meet the needs of general applications in terms of page elements, you can integrate with COM to obtain the extended functions.

This article provides a method to use python as the script language of the IE client. With the simplicity and scalability of Python, web applications can achieve better interaction on the client. You can also use Python's built-in network functions to implement Ajax functions more easily.

According to the Javascript syntax used in IE, you can guess that the python syntax used in IE is:

<Script language = "Python">

# Python code

</SCRIPT>

When ie executes this code, it needs to call the python interpreter to execute the code between <script language = "Python"> </SCRIPT>. Therefore, let ie identify the Python code, you need to tell ie where to find the python interpreter.

This function has been implemented in Python for Windows extension. In addition to client script support, this extension also includes server script, COM, and Windows GUI support.

First, download a python installation package from www.python.org, and then install it on the local hard disk. Assume that python is installed in C:/python24 and add the path to the environment variable path. For detailed installation, see the python manual.

Then download a python for Windows extension from the http://starship.python.net/crew/mhammond/, which is an installation package that requires you to specify the installation directory for python, which will install some files to C: /python24/lib/Site-packages directory.

Switch to the command line mode and run Python pyscript in the directory c:/python24/lib/Site-packages/win32comext/axscript/client. py and Python pyscript_rexec.py, register Python Windows Script to windows, so that IE can recognize Python scripts in HTML code.

The following is a Python code running in IE. To run it, you only need to save it in an HTM file and open it with IE. Click OK to display the three dialog boxes.

<HTML>

<Body>

<H1> embedded code Demo: python

<Script language = "Python">

Def show ():

For I in range (3 ):

Alert ("python in IE ==>%d" % I)

</SCRIPT>

<Form name = "FM">

<Input name = "B1" type = "button" value = "OK" onclick = "show ()">

</Form>

</Body>

Due to the syntax requirements of Python, Def show () must start from the first column. There cannot be spaces or tabs before it to indent the code.

Running the Python script in IE can obtain the powerful functions of Python, but requires that the python interpreter and python for Windows extension be installed on the machine where Ie is located. This limits the possibility of use in general web applications. However, it can be used in the following modes.

The client uses ie as the running container. The Python interpreter and Windows extension are installed on the client as part of the system, and even local databases are available. database operations are completed in the Python script, to interact with the server, use the Python script to exchange data with the server. This mode integrates the advantages of C/S and B/S. The client does not need to install special client software, and does not need to connect to the server from time to time, and does not need to manage session and other status information, you can connect to the server to send or obtain data after the service is completed offline.

Compared with XMLHTTP in Ajax to implement network functions, Python provides better and stronger functions and provides more concise encoding.

References

Mark Hammond, Andy Robinson Python programming on Win32, 2000 o'reilly


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.