Several common modules of Python

Source: Internet
Author: User

First, Sys

Used to provide actions related to the Python interpreter:


SYS.ARGV command line argument list, the first element is the program itself path Sys.exit (n) exits the program, exit normally (0) sys.version Gets the version information of the Python interpreter Sys.maxint the largest int value Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing Sys.platform Returns the operating system platform name Sys.stdin input related sys.stdout output related sys.stderror error related






Second, OS

Used to provide system-level operations:

OS.GETCWD () Gets the current working directory, that is, the directory path of the current Python script work os.chdir ("DirName") changes the current script working directory, equivalent to the shell Cdos.curdir Return to current directory: ('. ') Os.pardir Gets the parent directory string name of the current directory: (' ... ') Os.makedirs (' Dir1/dir2 ') can generate a multi-level recursive directory Os.removedirs (' dirname1 ') if the directory is empty, then deleted, and recursively to the previous level of the directory, if also empty, then delete, and so on Os.mkdir (' DirName ' Generate a single-level directory, equivalent to the shell mkdir dirnameos.rmdir (' dirname ') delete the single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to RmDir dirnameos.listdir in the shell (' dirname ') lists all files and subdirectories under the specified directory, including hidden files, and prints os.remove () Delete a file Os.rename ("Oldname", "new") Rename File/directory OS                  . Stat (' Path/filename ') gets file/directory information OS.SEP operating system-specific path delimiter, win under "\ \", Linux for "/" Os.linesep The current platform uses the line terminator, win under "\t\n", Linux for "\ n" os.pathsep the string used to split the file path Os.name string indicates the current use of the platform. Win-> ' NT ';       Linux-> ' POSIX ' Os.system ("Bash command") runs a shell command that directly displays the Os.environ get system environment variable Os.path.abspath (PATH) Return path normalized absolute path Os.path.split (path) splits path into directory and file name two tuples return Os.pathThe. DirName (path) returns the directory of path. In fact, the first element of Os.path.split (path) os.path.basename returns the last file name of path. If path ends with a/or \, then a null value is returned. The second element of Os.path.split (path), os.path.exists (path), returns True if path exists, or Falseos.path.isabs if path is not present if path is An absolute path that returns Trueos.path.isfile (path) If path is an existing file that returns TRUE. 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

Several common modules of Python

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.