Python Base Module

Source: Internet
Author: User

First, Introduction

The module is a file that holds the Python code. Modules can define functions, classes, and variables. The module can also contain executable code, the module is divided into three kinds:

    • Custom Modules
    • Built-in standard modules
    • Open source module (third party)

Second, commonly used built-in modules

  1. OS Module

    Role:

    Used to provide system-level operations

    Function:

    OS.GETCWD () Gets the current working directory, which is the directory path of the current Python script work os.chdir ("dirname") To change the current script working directory, equivalent to the shell under Cdos.curdir return to the current directory: ('.') Os.pardir Gets the parent directory string name of the current directory: ('..') Os.makedirs ('Dir1/dir2') to generate a multi-level recursive directory Os.removedirs ('dirname1'If the directory is empty, it is deleted and recursively to the previous level of the directory, if it is also empty, then delete, and so on OS.mkdir('dirname') to generate a single-level directory, equivalent to mkdir in the shelldirnameOS.rmdir('dirname'Delete the single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to rmdir in the shelldirnameOs.listdir ('dirname'lists all files and subdirectories under the specified directory, including hidden files, and prints a list of os.remove () deletes a file Os.rename ("oldname","New") Rename File/directory OS.Stat('Path/filename') Get File/directory information OS.SEP operating system-specific path delimiter, win under"\\", under Linux for"/"Os.linesep The line terminator used by the current platform, win under"\t\n", under Linux for"\ n"os.pathsep The string Os.name string used to split the file path indicates the current usage platform. Win-'NT'; Linux->'POSIX'Os.system ("Bash Command"run the shell command to directly display the Os.environ get system environment variable Os.path.abspath (PATH) returns path normalized absolute path Os.path.Split(path) splits path into directory and file name two tuples return Os.path.dirname(path) Returns the directory of path. is actually os.path.Splitthe first element of the (path) Os.path.basename(path) Returns the last file name of path. If path ends with a/or \, then a null value is returned. That is Os.path.Splitthe second element of path, os.path.exists (path), returns True if path exists, or if path does not exist, returns Falseos.path.isabs (path) If path is an absolute path and returns TRU Eos.path.isfile (path) returns True if path is a file that exists. Otherwise, return Falseos.path.isdir (path) True if path is a directory that exists. Otherwise, return Falseos.path.Join(path1[, path2[, ...]) When multiple paths are combined and returned, the parameters before the first absolute path are ignored Os.path.getatime (path) returns the file or directory to which path points to the last access time Os.path.getmtime (path) returns the file or directory that the path points to The last modified time
    View Code
  2. SYS module
  3. Time Module
  4. DateTime module
  5. Pickle Module
  6. Random module
  7. Hashlib Module

Python Base Module

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.