Common Python modules (OS module) and pythonos Module

Source: Internet
Author: User

Common Python modules (OS module) and pythonos Module
I. Introduction to the Python OS Module

The OS module is a Python System Programming operation module that can process files and directories.

You can view the help documentation of the OS module:

>>> Import OS # import OS Module
>>> Help (OS) # view the help document of the OS module, including the detailed module functions and usage methods.

Ii. Important functions and variables of the OS module:


1) OS. sep changes the path Separator in the operating system.
2) OS. getcwd () to obtain the current path, which is commonly used in Python code.
3). OS. listdir () lists all files and folders in the current directory.
4) The OS. remove () method can delete the specified file.
5) The OS. system () method is used to run shell commands.
6) OS. chdir () changes the current directory to the specified directory.

Iii. Explanation of functions of the OS Module

The OS. system function can run the shello command. in Linux, It is the command in the terminal simulator.
Some functions can also execute external programs, including execv, which will exit the Python interpreter and give control to the executed program.

The OS. sep variable is mainly used as a separator IN THE SYSTEM path.
For Windows systems, the Delimiter is "\", for Linux systems such as Ubuntu, the separator is "/", and for Mac OS systems, the separator is ":".

Iv. OS module case code demonstration

 

Summary:OS ModuleSystem files and directories are used in many ways and are also common modules. You must master the knowledge. This is a typical cross-platform module in the Python standard library, supports Windows, Linux, and other system operations without modifying any code or generating errors.

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.