Build python environment and Python file types

Source: Internet
Author: User

    • Linux Environment

      -The Python environment is installed by default for most Linux distributions.

      -Enter Python to launch Python interactive mode

      -Recommended use of VIM for program editors

    • Windows environment

      -Download the MSI package to install Python directly

      -A GUI development environment that comes with Python

      -Many development tools

# Linux Interactive interface [[email protected] ~]# Pythonpython 2.6.6 (r266:84292, Jan, 09:37:14) [GCC 4.4.7 20120313 (Red Hat 4.4.7 -4)] on Linux2type ' help ', ' copyright ', ' credits ' or ' license ' for more information.# exit instruction >>>exit () [[Email Protec Ted] ~]## text mode [[email protected] ~]# vim 1.pyprint ' Hello world ' [[email protected] ~]# python 1.pyhello world>>> print ' Hello world ' Hello world>>> exit () [[email protected] ~]#


Python file types

    • Source

-Python source code file with "py" as extension, interpreted by Python program, do not need to compile

[[email protected] ~]# vim 1.py# python standard format #!/usr/bin/pythonprint ' Hello World ' [[email protected] ~]# chmod +x 1.py[[email Protected] ~]# ls-l 1.py-rwxr-xr-x 1 root root 39 June 08:59 1.py[[email protected] ~]#./1.pyhello World
    • BYTE code

      -Python source files are compiled and produced with the extension "PYc" files

# Introducing modules, compiling for 1.py [[email protected] shell]# vim 2.pyimport py_compilepy_compile.compile ("1.py") # Compiling with Python [[email Protected] shell]# python 2.py[[email protected] shell]## This generates a file that ends in PYC [[email protected] shell]# ls-l Total usage 12-rwxr-xr- X 1 root root 39 June 08:59 1.py-rw-r--r--1 root root 112 June 10:37 1.pyc-rwxr-xr-x 1 root root 46 June 21 10:37 2. py# This file can also be executed [[email protected] shell]# python 1.pychello World
    • Optimized code

      -Optimized source file with "pyo" extension

[[email protected] shell]# Python-o-M py_compile 1.py[[email protected] shell]# ls-l Total usage 16-rwxr-xr-x 1 root root 39 June  08:59 1.py-rwxr-xr-x 1 root root 112 June 10:37 1.pyc-rwxr-xr-x 1 root root 112 June 10:44 1.pyo-rwxr-xr-x 1 root Root 46 June 10:37 2.py


Three kinds of code execution effects

[[email protected] shell]# python 1.pyhello world[[email protected] shell]# python 1.pychello world[[email protected] Shel l]# python 1.pyohello World


This article is from the "topspeed_king" blog, make sure to keep this source http://mylinuxlife.blog.51cto.com/4706737/1664026

Build python environment and Python file types

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.