First, OS
The OS module contains common operating system features:
Os.pardir #获取当前目录的父目录字符串名: (' ... ') Os.makedirs (' dirname1/dirname2 ') #可生成多层递归目录os. Removedirs (' dirname1 ') #若目录为空, then delete, and recursively to the previous level of the directory, if also empty, then delete, and so on OS.M Kdir (' dirname ') #生成单级目录, equivalent to mkdir dirnameos.rmdir (' dirname ') in the shell #删除单级空目录, cannot be deleted if the directory is not empty , error, equivalent to RmDir dirnameos.listdir (' dirname ') #列出指定目录下的所有文件和子目录 in the shell, including hidden files, and printing in a list os.remove () #删除一个文件os. Rename ("Oldname", "newname") #重命名文件/directory Os.stat (' path/filename ') #获取文件/directory information OS.SEP #输出操作系统特定的路径分隔符, win under "\ \", Linux for "/" Os.linesep #输出当前平台使用的行终止符, WI N is "\t\n" and Linux is "\ n" os.pathsep #输出用于分割文件路径的字符串os. Name #输出字符串指示当前 Use the platform. Win-> ' NT '; The linux-> ' POSIX ' Os.system ("Bash command") #运行shell命令 directly displays the Os.environ #获取系统环境变量os. PA Th.abspath (Path) #返回path规范化的绝对路径os. Path.split (Path) #将path分割成目录和文件名二元组返回os. Path.dirname (Path) #返回path的目录. The first element of Os.path.split (path) is actually the #返回path最后的文件名 of the Os.path.basename (path). If path ends with a/or \, then a null value is returned. That is, the second element of Os.path.split (path) is #如果path存在, returns True, or Falseos.path.isabs (path) If path does not exist. #如果path是绝对路径, returns a Trueos.path.isfile (path) #如果path是一个存在的文件, which returns True. Otherwise, returns the Falseos.path.isdir (path) #如果path是一个存在的目录, which returns True. Otherwise return Falseos.path.join (path1[, path2[, ...]) #将多个路径组合后返回, the parameters before the first absolute path are ignored Os.path.getatime (path) #返回path所指向的文件或者目录的最后存取时间os. Path.getmtime (Path) #返回path所指向的文件或者目录的最后修改时间
Second, SYS
The SYS module provides a series of variables and functions for the Python runtime environment.
SYS.ARGV #命令行参数List, the first element is the program itself path Sys.exit (n) #退出程序, exit normally exits (0) sys.version # Gets the version information for the Python interpreter sys.maxint #最大的Int值sys. Path #返回模块的搜索路径, initialized with the value of the PYTHONPATH environment variable Sys.platform # Returns the operating system platform name
python-Common module OS, sys