- 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
- Parameter passing
When the interpreter is invoked, the script name and additional parameters are passed into asys.argv
List 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.argv
For the script command operation.
- 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