Python standard library is installed with Python, which contains a large number of extremely useful modules. It is very important to be familiar with the Python standard library, because if you are familiar with the modules in these libraries, most of your problems can be solved simply and quickly. You can learn the complete content of all modules in the Python standard library in the "Library Reference" section of the Python installation documentation. The sys module contains the system functions. My... Python Standard Library
The Python Standard Library is installed with Python and contains a large number of extremely useful modules. It is very important to be familiar with the Python standard library, because if you are familiar with the modules in these libraries, most of your problems can be solved simply and quickly.
You can learn the complete content of all modules in the Python standard library in the "Library Reference" section of the Python installation documentation.
Sys module
The sys module includes the system functions. We have learned the sys. argv list, which contains command line parameters.
OS module
This module contains common operating system functions. This module is especially important if you want your program to be unrelated to the platform. That is, it allows a program to run in Linux and Windows without any changes or any problems. In one example, OS. sep can replace the path delimiter specified by the operating system.
The following lists some useful parts in the OS module. Most of them are simple and clear.
● The OS. name string indicates the platform you are using. For example, for Windows, it is 'nt ', and for Linux/Unix users, it is 'posix '.
● The OS. getcwd () function obtains the current working directory, that is, the directory path of the current Python script.
● The OS. getenv () and OS. putenv () functions are used to read and set environment variables respectively.
● OS. listdir () returns all files and directory names under the specified directory.
● The OS. remove () function is used to delete an object.
● The OS. system () function is used to run shell commands.
● The OS. linesep string provides the row Terminator used by the current platform. For example, in Windows, '\ r \ n' is used, in Linux,' \ n' is used, and in Mac, '\ r' is used '.
● The OS. path. split () function returns the directory name and file name of a path.
● The OS. path. isfile () and OS. path. isdir () functions verify whether the given path is a file or a directory. Similarly, the OS. path. exists () function is used to check whether the given path actually exists.
You can use the Python standard documentation to explore more details about these functions and variables. You can also use help (sys) and so on.