Python Standard library-os

Source: Internet
Author: User

Common methods of OS modules
Module Method Description
OS.GETCWD () Gets the current working directory, which is the directory path of the current Python script work
Os.chdir ("DirName") Change the current script working directory, equivalent to the shell CD
Os.curdir Return to current directory: ('. ')
Os.pardir Gets the parent directory string name of the current directory: (' ... ')
Os.makedirs (' dirname1/dirname2 ') Multi-level recursive catalogs can be generated
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 ') Generate a single-level directory, equivalent to the shell mkdir dirname
Os.rmdir (' dirname ') Delete single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to the shell rmdir dirname
Os.listdir (' dirname ') Lists all files and subdirectories under the specified directory, including hidden files, and prints as a list
Os.remove () Delete a file
Os.rename ("Oldname", "NewName") Renaming files/Directories
Os.stat (' Path/filename ') Get File/directory information
Os.sep Output operating system-specific path delimiter, win under \\ , Linux for/
Os.linesep Output the line terminator used by the current platform, win under \t\n , Linux for\n
Os.pathsep Output a string used to split a file path
Os.name The output string indicates the current usage platform. Win-> nt ; Linux->posix
Os.system ("Bash command") Run the shell command to display directly
Os.environ Get System Environment variables
Os.path.abspath (PATH) Returns the absolute path normalized by path
Os.path.split (PATH) Split path into directory and file name two tuples returned
Os.path.dirname (PATH) Returns the directory of path. is actually the first element of Os.path.split (path)
Os.path.basename (PATH) Returns the last file name of path. A \ null value is returned if the path is or ends. The second element of Os.path.split (path)
Os.path.exists (PATH) Returns true if path exists, false if path does not exist
Os.path.isabs (PATH) Returns true if path is an absolute path
Os.path.isfile (PATH) Returns true if path is a file that exists. otherwise returns false
Os.path.isdir (PATH) Returns true if path is a directory that exists. otherwise returns false
Os.path.join (path1[, path2[,...]]) When multiple paths are combined, the parameters before the first absolute path are ignored
Os.path.getatime (PATH) Returns the last access time of the file or directory to which path is pointing
Os.path.getmtime (PATH) Returns the last modified time of the file or directory to which path is pointing

Python Standard library-os

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.