Python Module Base OS module

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.