The OS module is simply a python system-programmed operating module that can handle files and directories that we manually need to do on a daily basis.
You can view the Help documentation for the OS module:
>>> Import OS #导入os模块
>>> Help (OS) #查看os模块帮助文档, with detailed module-related functions and how to use them
Second, the OS module important functions and variables:
1), OS.SEP change the path delimiter in the operating system.
2), OS.GETCWD () Gets the current path, which is more commonly used in Python code.
3), Os.listdir () lists all files and folders in the current directory.
4), Os.remove () method to delete the specified file.
5), the Os.system () method is used to run the shell command.
6), Os.chdir () change the current directory to the specified directory.
Third, the OS module function of the detailed
The Os.system function can run the Shello command, which is the command in the terminal emulator on the Linux system.
There are also functions that can execute external programs, including EXECV, which exits the Python interpreter and gives control to the executed program.
The OS.SEP variable is used primarily for separators in the system path.
Windows system through is "\ \", Linux class system such as Ubuntu separator is "/", and Apple Mac OS system is ":".
Iv. OS module Case code Demo
Description: The above to play the snake network Leo only do a few simple OS module operation directory and file demonstration, if you are interested in learning more complex, more ingenious way to participate in our Python training course.
Summary:OS module in the system files and directory operations used more, is also our common module, we must master the knowledge, which is a typical Python standard cross-platform module, support Windows and Linux system operations, without modifying any code, No errors are generated.
Python Module Base OS module