Installation and configuration of Python scripts

Source: Internet
Author: User

Python scripts are widely used. In this process, we will see various problems. In fact, you only need to study it carefully. Next we will take a detailed look at the relevant technical information. I hope you will have some gains.

Currently, many third-party scripting languages are available for direct use, such as Tcl and Lua. This article describes Python scripts. Python has more than a decade of history. It is an explanatory and object-oriented scripting language. Python interpreters can run on most operating systems, such as Windows, Linux, Solaris, and Mac.

1. installation and configuration

The latest version of Python script is 2.3.2. This article uses 2.2.2. After running the installation program, it will install the Python interpreter, documentation, extension module, and so on to your computer. After the installation is complete, the Python Graphical Editor (IDLE, but Chinese characters are not supported in the current version), Python command line interpreter, and user manual will be displayed in the Start Menu.

To call the Python API function in a C ++ program, you need to add the header file and lib path to the search directory of VC ++, the header file path is the include directory under the Local Python installation directory, and the lib path is the libs directory under the Local Python installation directory. Note that the installation package only provides the lib and dll of the release version. If debugging is required, you must download the Python source code to compile the lib and dll of the debug version.

2. Syntax Introduction

For detailed syntax instructions, refer to the documentation that comes with the Python script installation package. Here I will only introduce some common keywords and precautions.

Python does not include {And} in C ++. It is replaced by indentation. Variables do not need to be declared separately, but cannot reference unassigned variables.

The Python script introduces the concept of a module, similar to the concept of Library in C ++. A module can contain functions, variables, and classes. A script file is a module that needs to be imported before use. Python does not have a switch. if is used instead:

 
 
  1. if ( num==1 ):  
  2. print "1"  
  3. elif ( num==2 ):  
  4. print "2"  
  5. else:  
  6. print "unknown" 

While is a loop Statement of Python. In the while LOOP, you can use continue to jump to the next loop, and use break to jump out of the entire loop:

 
 
  1. cnt = 5 
  2. while ( cnt > 0 ):  
  3. print cnt  
  4. cnt -= 1 

For Loop:

 
 
  1. list = ["test1", "test2", "test3"]  
  2. for str in list:  
  3. print str 

A dictionary is a type of ing data for Python scripts. It can be mapped from a key to the actual content (value ):

 
 
  1. accounts = {'tom':'123456', 'mike':'654321'}  
  2. print accounts['tom']  
  3. print accounts['mike'] 

The above describes how to install and configure Python scripts.

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.