Built-in application modules list of modules sys module

os module

os module

os module is responsible for programs interact with the operating system, provides the interface to access the underlying operating system, used for file handling.

method Detailed
os.getcwd() Gets the current working directory that the current directory path python script work
os.chdir("dirname") Script to change the current working directory; cd at the equivalent of shell
os.curdir Returns the current directory: ( '.')
os.pardir Get the current directory's parent directory string name :( '..')
os.makedirs('dirname1/dirname2') The multilayer recursive directory may be generated
os.removedirs('dirname1') If the directory is empty, delete, and recursively to the parent directory, should also empty, delete, and so on
os.mkdir('dirname') Generating a single level directory; is equivalent to the shell mkdir dirname
os.rmdir('dirname') Delete single stage empty directory, if the directory is not empty can not be deleted, an error; the equivalent of a shell rmdir dirname
os.listdir('dirname') Lists all the files and subdirectories in the specified directory, including hidden files, and print as a list
os.remove () Delete a file
os.rename("oldname","newname") Rename the file / directory
os.stat('path/filename') Get file / directory information
os.sep Output operation system-specific path separator, the win is "\", is the Linux "/"
os.linesep The current output line terminator platform, the win is "\ t \ n", as "\ n" under Linux
os.pathsep Win for the next character string for dividing the output file path;, under Linux is:
os.name It indicates the current output string using the internet. win -> 'nt'; Linux -> 'posix'
os.system("bash command") Run shell commands, direct display
os.environ Acquisition system environment variables
os.path.abspath(path) Returns the absolute pathname path of standardization
os.path.split(path) The path into the directory and file name of the tuple returned
os.path.dirname(path) Returns the directory path of. In fact, os.path.split (path) of the first element
os.path.basename(path) Returns the path of the last file name. How path to / \ or end, it will return a null value. That second element os.path.split (path) of
os.path.exists(path) If the path exists, return True; if the path does not exist, returns False
os.path.isabs(path) If the path is an absolute path, returns True
os.path.isfile(path) If the path is an existing file and returns True. Otherwise it returns False
os.path.isdir(path) If the path is a directory exists, then return True. Otherwise it returns False
os.path.join(path1[, path2[, ...]]) After combination of a plurality of paths returned, before the first parameter is ignored absolute path
os.path.getatime(path) Returns the last access time path points to a file or directory
os.path.getmtime(path) Returns the file or directory path points to the last modification time

os.path.getsize (path) returns the size of path

 

sys module

 

sys module

Responsible for interacting with the python interpreter program provides a set of functions and variables to control when running python environment.

method Detailed
sys.argv Command line parameters List, the first element is the path to the program itself
sys.modules.keys() Returns a list of all the imported modules
sys.exc_info() 获取当前正在处理的异常类,exc_type、exc_value、exc_traceback当前处理的异常详细信息
sys.exit(n) 退出程序,正常退出时exit(0)
sys.hexversion 获取Python解释程序的版本值,16进制格式如:0x020403F0
sys.version 获取Python解释程序的版本信息
sys.maxint 最大的Int值
sys.maxunicode 最大的Unicode值
sys.modules 返回系统导入的模块字段,key是模块名,value是模块
sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.platform 返回操作系统平台名称
sys.stdout 标准输出
sys.stdin 标准输入
sys.stderr 错误输出
sys.exc_clear() 用来清除当前线程所出现的当前的或最近的错误信息
sys.exec_prefix 返回平台独立的python文件安装的位置
sys.byteorder 本地字节规则的指示器,big-endian平台的值是'big',little-endian平台的值是'little'
sys.copyright 记录python版权相关的东西
sys.api_version 解释器的C的API版本

os模块负责程序与操作系统的交互,提供了访问操作系统底层的接口,多用于文件处理。

方法 详解
os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径
os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd
os.curdir 返回当前目录: ('.')
os.pardir 获取当前目录的父目录字符串名:('..')
os.makedirs('dirname1/dirname2') 可生成多层递归目录
os.removedirs('dirname1') 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推
os.mkdir('dirname') 生成单级目录;相当于shell中mkdir dirname
os.rmdir('dirname') 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname
os.listdir('dirname') 列出指定目录下的所有文件和子目录,包括隐藏文件,并以列表方式打印
os.remove() 删除一个文件
os.rename("oldname","newname") 重命名文件/目录
os.stat('path/filename') 获取文件/目录信息
os.sep 输出操作系统特定的路径分隔符,win下为"\",Linux下为"/"
os.linesep 输出当前平台使用的行终止符,win下为"\t\n",Linux下为"\n"
os.pathsep 输出用于分割文件路径的字符串 win下为;,Linux下为:
os.name 输出字符串指示当前使用平台。win->'nt'; Linux->'posix'
os.system("bash command") 运行shell命令,直接显示
os.environ 获取系统环境变量
os.path.abspath(path) 返回path规范化的绝对路径
os.path.split(path) 将path分割成目录和文件名二元组返回
os.path.dirname(path) 返回path的目录。其实就是os.path.split(path)的第一个元素
os.path.basename(path) 返回path最后的文件名。如何path以/或\结尾,那么就会返回空值。即os.path.split(path)的第二个元素
os.path.exists(path) 如果path存在,返回True;如果path不存在,返回False
os.path.isabs(path) 如果path是绝对路径,返回True
os.path.isfile(path) 如果path是一个存在的文件,返回True。否则返回False
os.path.isdir(path) 如果path是一个存在的目录,则返回True。否则返回False
os.path.join(path1[, path2[, ...]]) 将多个路径组合后返回,第一个绝对路径之前的参数将被忽略
os.path.getatime(path) 返回path所指向的文件或者目录的最后存取时间
os.path.getmtime(path) 返回path所指向的文件或者目录的最后修改时间

os.path.getsize(path) 返回path的大小

 

sys模块

 

sys模块

负责程序与python解释器的交互,提供了一系列的函数和变量,用于操控python的运行时环境。

方法 详解
sys.argv 命令行参数List,第一个元素是程序本身路径
sys.modules.keys() 返回所有已经导入的模块列表
sys.exc_info() 获取当前正在处理的异常类,exc_type、exc_value、exc_traceback当前处理的异常详细信息
sys.exit(n) 退出程序,正常退出时exit(0)
sys.hexversion 获取Python解释程序的版本值,16进制格式如:0x020403F0
sys.version 获取Python解释程序的版本信息
sys.maxint 最大的Int值
sys.maxunicode 最大的Unicode值
sys.modules 返回系统导入的模块字段,key是模块名,value是模块
sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.platform 返回操作系统平台名称
sys.stdout 标准输出
sys.stdin 标准输入
sys.stderr 错误输出
sys.exc_clear() 用来清除当前线程所出现的当前的或最近的错误信息
sys.exec_prefix 返回平台独立的python文件安装的位置
sys.byteorder 本地字节规则的指示器,big-endian平台的值是'big',little-endian平台的值是'little'
sys.copyright 记录python版权相关的东西
sys.api_version 解释器的C的API版本

sys模块

负责程序与python解释器的交互,提供了一系列的函数和变量,用于操控python的运行时环境。

方法 详解
sys.argv 命令行参数List,第一个元素是程序本身路径
sys.modules.keys() 返回所有已经导入的模块列表
sys.exc_info() 获取当前正在处理的异常类,exc_type、exc_value、exc_traceback当前处理的异常详细信息
sys.exit(n) 退出程序,正常退出时exit(0)
sys.hexversion 获取Python解释程序的版本值,16进制格式如:0x020403F0
sys.version 获取Python解释程序的版本信息
sys.maxint 最大的Int值
sys.maxunicode 最大的Unicode值
sys.modules 返回系统导入的模块字段,key是模块名,value是模块
sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.platform 返回操作系统平台名称
sys.stdout 标准输出
sys.stdin 标准输入
sys.stderr 错误输出
sys.exc_clear() 用来清除当前线程所出现的当前的或最近的错误信息
sys.exec_prefix 返回平台独立的python文件安装的位置
sys.byteorder 本地字节规则的指示器,big-endian平台的值是'big',little-endian平台的值是'little'
sys.copyright 记录python版权相关的东西
sys.api_version 解释器的C的API版本

Guess you like

Origin www.cnblogs.com/jiangxianseng/p/11879448.html