Python tutorial reading using the Python interpreter

Source: Internet
Author: User

  1. After you configure environment variables, you can typically call Python directly from Python or by specifying a python version number.

    The Python interpreter operates like a Unix shell: it interactively interprets and executes commands when using a terminal device (TTY) as a standard input call, reads the file and executes the file as a script when using the file name parameter or as a file as a standard input.

    PYTHON-M module name [arg] ... #可以直接执行模块, similar to reading files directly and executing as scripts

    1 #  2"print (' Hello World ')"3 $ Hello World
  2. Parameter passing

    When the interpreter is invoked, the script name and additional parameters are passed into asys.argvList of strings. You can get this list by executingimport sys, the length of the list is greater than or equal to 1, and there is at least one element when no script or parameter is given:sys.argv[0]This is an empty string. The script name is specified as‘-‘(indicates standard input),sys.argv[0]is set to‘-‘, using the-CinstructionWhensys.argv[0]is set to‘-c‘。 Using-MModuleparameter,sys.argv[0]is set to the full name of the specified module. -CinstructionOr-MModuleThe following parameters are not intercepted by the Python interpreter's option handling mechanism, but are left insys.argvFor the script command operation.

  3. Specify encoding

#-*-Coding:utf-8-*-

Special encoding annotations must be defined in the first or second row of the file.

Python tutorial reading using the Python interpreter

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.