Python Learning--python Standard library

Source: Internet
Author: User
Python Standard library

The Python standard library is installed with Python, and it contains a number of extremely useful modules. It is important to familiarize yourself 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 full contents of all the modules in the Python standard library in the "Library references" section of the documentation that accompanies the installation in Python.

SYS module

The SYS module contains the functions that the system corresponds to. We have learned the SYS.ARGV list, which contains command line arguments.

OS Module

This module contains common operating system functions. This module is especially important if you want your program to be platform-agnostic. That is, it allows a program to be written without any changes or problems, and can be run under Linux and Windows. An example is the use of OS.SEP to replace the operating system-specific path delimiters.
Some of the more useful parts of the OS module are listed below. Most of them are simple and straightforward.
The Os.name string indicates the platform you are using. For example, for Windows, it's ' NT ', and for Linux/unix users, it's ' POSIX '.
The OS.GETCWD () function gets the current working directory, which is the directory path of the current Python script work.
The Os.getenv () and os.putenv () functions are used to read and set environment variables, respectively.
Os.listdir () returns all file and directory names under the specified directory.
The Os.remove () function is used to delete a file.
The Os.system () function is used to run the shell command.
The OS.LINESEP string gives the line terminator used by the current platform. For example, Windows uses ' \ r \ n ', Linux uses ' \ n ' and Mac uses ' \ R '.
The Os.path.split () function returns the directory name and file name of a path.
The Os.path.isfile () and Os.path.isdir () functions respectively verify that the given path is a file or a directory. Similarly, the os.path.exists () function is used to verify that the given path really exists.
You can use the Python standard documentation to explore more detailed knowledge of these functions and variables. You can also use Help (SYS) and so on.

  • 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.