The sys module in python is a module used to handle the python runtime environment. It provides many functions and variables to handle different parts of the python runtime environment.
#Nowadays, more and more friends are learning Python. And it also has many puzzling knowledge points that require everyone to find information and learn about it. Next I will tell you what the python sys module is.
The sys module in Python is a module used to handle the Python runtime environment. It provides many functions and variables to handle different parts of the Python runtime environment.
The following is a list of common functions of the sys module:
sys.argv: implements passing parameters to the program from outside the program.
sys.exit([arg]): Exit in the middle of the program, arg=0 means normal exit.
sys.getdefaultencoding(): Gets the current encoding of the system, which generally defaults to ascii.
sys.setdefaultencoding(): Set the system default encoding. You will not see this method when executing dir (sys). If the execution fails in the interpreter, you can execute reload (sys) first, and then execute setdefaultencoding( 'utf8'), at this time the system default encoding is set to utf8. (See setting the system default encoding)
sys.getfilesystemencoding(): Gets the encoding used by the file system. It returns 'mbcs' under Windows and 'utf-8' under mac.
sys. path: Get the string collection of the specified module search path. You can put the written module under a certain path obtained, and you can find it correctly when importing in the program.
sys.platform: Get the current system platform.
sys.stdin, sys.stdout, sys.stderr: The stdin, stdout, and stderr variables contain stream objects corresponding to the standard I/O streams. If you need more control over the output, and print does not satisfy you requirements, they are all you need. You can also replace them, in which case you can redirect output and input to other devices (devices), or handle them in non-standard ways.
The above is the detailed content of What does the sys module in python mean?. For more information, please follow other related articles on the PHP Chinese website!