OS Module
Provides an interface to invoke the operating system
ImportOSOS.GETCWD ()#get current working directoryOs.chdir (R'D:\fansik')#Modify the current working directoryPrint(Os.curdir)#returns the current directory (where return is the return value)Print(Os.pardir)#return to parent directoryOs.makedirs ('Fansik/fanjinbao')#Create the Fansik directory in the current working directory and create the Fanjinbao directory under the Fansik directory, rather like Mkdir-pOs.removedirs ('Fansik/fanjinbao')#Delete Empty directoryOs. mkdir ('Fansik')#equivalent to mkdir dirname without the-p parameterOs.rmdir ('Fansik')#equivalent to a single-level catalogPrint(Os.listdir ())#returns all files under the current working directoryOs.remove ('fansik.py')#Delete Files onlyOs.rename ('fansik.py','fanjinbao.py')#file RenamePrint(Os.stat ('fanjinbao.py'))#Show file PropertiesPrint(OS.SEP)#System record Path delimiter (paths that are stitched together in this way can be used for different operating systems)Print(OS.LINESEP)#line break: Windows is \ r \ n, Linux is n\, Mac is \ rPrint(OS.PATHSEP)#environment variable Path separator, Windows is semicolon, Linux is colonOs.name#The output string indicates the current usage platform. Win-> ' NT '; Linux-> ' POSIX 'Os.system ("Bash Command")#run the shell command to display directlyOs.environ#Get system Environment variablesOs.path.abspath ('d:/fansik/day_01')#returns the absolute path normalized by pathOs.path.split (PATH)#split path into directory and file name two tuples returnedOs.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. 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, false if path does not existOs.path.isabs (PATH)#returns True if path is an absolute pathOs.path.isfile (PATH)#returns True if path is a file that exists. Otherwise returns falseOs.path.isdir (PATH)#returns True if path is a directory that exists. Otherwise returns falseOs.path.join (path1[, path2[, ...])#when multiple paths are combined, the parameters before the first absolute path are ignoredOs.path.getatime (PATH)#returns the last access time of the file or directory to which path is pointingOs.path.getmtime (PATH)#returns the last modified time of the file or directory to which path is pointing
SYS module
SYS module interacting with the Pyhton interpreter
Import# command line argument list, the first element is the program itself path # exit program, Exit normally (0)sys.version # get version information for Python interpreter 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
Python basic-os and SYS modules