Day5 module learning-sys module, day5 module-sys
Sys module
The sys module is a system-related module. The following describes common methods of the sys module:
1. sys. argv # command line parameter list. The first element is the program path.
2. sys. exit (n) # exit the program. exit (0) when the program Exits normally)
Function: run to the end of the main program, The interpreter automatically exits, but if you need to exit the program halfway, you can call sys. the exit function, with an optional integer parameter returned to the program that calls it, indicates that you can capture the sys. exit call. (0 indicates normal exit, and others indicate exceptions)
Sys. exit (0) indicates that the system Exits normally. Otherwise, the system exits abnormally.
3. sys. version # obtain the version information of the python interpreter.
>>> Sys. version
'3. 5.2 (default, Nov 17 2016, 17:05:23) \ n [GCC 5.4.0 20160609]
4. sys. path
# Obtain the string set of the specified module search path. You can place the written module in a specific path to find the correct string in the program import.
>>> Sys. path
['', '/Usr/local/lib/python3.5/dist-packages/pygame-1.9.4.dev0-py3.5-linux-x86_64.egg', '/usr/lib/python35.zip', '/usr/lib/python3.5 ', '/usr/lib/python3.5/load', '/usr/lib/python3.5/lib-dynload', '/home/zhuzhu /. local/lib/python3.5/site-packages ','/usr/local/lib/python3.5/dist-packages ','/usr/lib/python3/dist-packages ']
Sys. path. append (custom file path) is used to add a custom file path. It is used to add environment variables when calling a file during program writing.
5. sys. modules
Function: sys. modules is a global dictionary that is loaded into the memory after python is started. Every time a programmer imports a new module, sys. modules automatically records the module. When the module is imported again for the second time, python will directly search for it in the dictionary, thus speeding up the program running. It has all the methods that the dictionary has.
Sys. modules contains sys. modules. keys () and sys. modules. values ().
6. sys. stdin \ stdout \ stderr
Function: stdin, stdout, and stderr variables include stream objects corresponding to standard I/O streams. If you need to better control the output, print cannot meet your requirements, they are what we need. We can replace them. In this case, we can redirect the output to another device, or process them in a non-standard way.
7. sys. platform # Return the operating system platform name
>>> Sys. platform
'Linux'