Basic Python notes-debugging and running

Source: Internet
Author: User
Python is an object-oriented interpreted language and an open-source scripting language (which emphasizes development speed and code Clarity ). As a beginner, you must first understand how to run what you write. I have mentioned how to install it in introduction, but it is not repeated here.

 

Before Running python, you have to mention the Compiling Style of Python. Python is designed to solve the problem of clear and maintainable code. Python syntax does not have "{...}" Braces and semicolons (;). Therefore, the statement is forced indent, which shows the statement logic in a clear indent format. Statements written without indentation may be interpreted incorrectly. (I personally prefer braces .) Generally, four spaces are used as an indent level. You can also use the indentation of eight spaces according to ide or your preferences. If a long line is folded, you can still use the backslash (/) to continue the line.

Call the python interpreter to run the written Python code. Here we will look at two basic forms: Interactive Mode and script execution mode.

I, Interactive Mode ):

That is, the console running that you have seen before. Take MS Windows as an example. Set environment variables, start the console, and type python. If the following prompt is displayed, the interactive running mode of python is successful:

python 


Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32


Type "help", "copyright", "credits" or "license" for more information.


>>>

Therefore, after >>> appears, you can write things later.

II, Script Execution Mode (Python script ):

If you want to save everything you write, you cannot write it directly on the console. The Python script can be considered as its source file. Creating a file is very simple. You can use any text editor you like to create a file and write it into a program. When saving the file, save the file extension as py, that is, *. py.

In Linux, Python scripts can be directly executed, just like normal bash scripts. The first line of the script must be logged in :#! /Usr/bin/ENV python, and then execute the permission: $ chmod + x myscript. py. In this way, you can run it like a normal script.

In Windows, using the built-in idle after installation is a good choice (but I cannot afford this in WINXP, somehow ). Now I am using eclipse, which has some advantages in writing and debugging. Of course, it is convenient to write something small without using ide. For notepad or editplus J. After writing something, remember to save it as the suffix of. py, for example, myscript. py. After the file icon is displayed, it becomes a green snake. CMD first, go to the path where the script is saved, and create Python myscript. py after the DOS character. The script will be executed.

For script editing, you must pay attention to the "indent" mentioned above. Otherwise, errors will certainly occur during execution.

/*

Now that you are talking about eclipse, let's talk about how to turn eclipse into Python IDE. The simplest method is to directly put the update address of the pydev plug-in into the Update column of Eclipse. Select help> Software Updates> Update manager from eclipse to start the install/update perspective. The URL of the update site is http://pydev.sf.net/updates/. after the update, you can download and update the site in one step. If you are interested, please refer to "Python development with eclipse and ant" (http://www-128.ibm.com/developerworks/cn/opensource/os-ecant/index.html) on the IBM website.
*/

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.