"Python module learning" OS module

Source: Internet
Author: User
Tags parent directory python script

The OS module operates as follows:

1OS.GETCWD ()#gets the current working directory, which is the directory path of the current Python script work2Os.chdir ("dirname")#change the current script working directory, equivalent to the shell CD3Os.curdir#return to current directory: ('. ')4Os.pardir#Gets the parent directory string name of the current directory: (' ... ')5Os.makedirs ('dirname1/dirname2')#Multi-level recursive catalogs can be generated6Os.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 on7Os.mkdir ('dirname')#generate a single-level directory, equivalent to the shell mkdir dirname8Os.rmdir ('dirname')#Delete single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to the shell rmdir dirname9Os.listdir ('dirname')#lists all files and subdirectories under the specified directory, including hidden files, and prints as a listTenOs.remove ()#Delete a file OneOs.rename ("oldname","newname")#Renaming files/directories AOs.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 "\ n" theOs.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) AOs.path.basename (PATH)#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) atOs.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 inOs.path.getmtime (PATH)#returns the last modified time of the file or directory to which path is pointing

"Python module learning" OS 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.