First, import SYS module operation
First, open the terminal emulator into the Python interpreter or open the IDE editor to create a new Python program file for the. py suffix name.
Here is an example of an action in the interpreter:
>>> Import SYS #导入sys模块
>>> dir (SYS) #dir () method to view the methods available in the module
Note: If you are in the editor, be careful to declare the code in advance, otherwise the Chinese will be garbled.
Second, SYS module important function variables
1), Sys.stdin standard input stream.
2), sys.stdout standard output stream.
3), Sys.stderr standard error stream.
4), the directory Name list of the directory where the Sys.path lookup module is located.
5), sys.argv the command line parameters, including the script name.
6), Sys.platform return to the current system platform, such as: Win32, Linux and so on.
Third, the use of the Sys method of instruction
Sys.exit method can exit the current program, can provide an integer type, usually we use 0 to represent the function, as the parameter of this method,
Of course, you can also use a string parameter, indicating the error message is unsuccessful.
The Sys.modules method maps the name of the module to a module that is actually present and applies only to modules that are currently imported.
There are 3 module variables: Sys.stdin, sys.stdout, Sys.stderr They are class file (File-like) stream objects.
Four, sys module case code demo
Above is the demo code for the Python sys module, and the gray part below is the output.
Five, sys module Tutorial Summary:
All the tutorials of the snake Network Python source code is in the Linux Ubuntu System test run, you can also self-debugging, improve their hands-on problem-solving ability.
SYS and OS modules are often used in our daily operating system editing, which is a must-know knowledge, we should practice more.
Play Snake net article, reprint please indicate the source and article URL: http://www.iplaypy.com/module/sys.html
Common modules in Python (SYS module)