Python learning-Python Standard Library

Source: Internet
Author: User
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.

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.