Python Basic Learning OS module and SYS module

Source: Internet
Author: User

OS module and SYS module
Import OS
OS.GETCWD () #获取当前工作目录
Os.chdir () #切换目录
Os.makedirs () #递归创建一个目录
Os.removedirs () #递归删除一个目录 (if the directory is empty, it is deleted and recursively to the previous directory, if it is empty and then deleted, recursively to the previous level)
Os.mkdir () #不递归创建目录
Os.rmdir () #不递归删除目录
Os.listdir () #查看指定目录下的所有文件和目录
Os.remove () #删除一个文件
Os.rename (Oldname,newname) #重命名文件或目录
Os.stat () #获取一个文件或目录的信息

System-related
Os.sep #输出当前操作系统特定的路径分隔符 (window: \ \ linux/)
OS.LINSEP output line break for the current operating system (Windows is \ r \ n linux \ n)
OS.PATHSEP outputs the specific delimiter used by the current system to separate the path of the environment variable (Windows is; Linux as:)
Os.environ output The current system's environment variables
Os.name Output Current system name
Os.system () Execute system command


PATH
Os.path.abspath (PATH) # Gets the absolute path of a file
Os.path.split (path) #分割文件的路径, returns a tuple, the first part is a path, and the second part is a file name
Os.path.dirname (PATH) #返回path的目录路径
Os.path.basename (PAHT) #返回Path的文件名
Os.path.join (path1,path2) #将多个路径组合后返回, automatically using system-specified path separators in the middle of the path
Os.path.getatime (PATH) #返回文件或目录的最后读取时间
Os.path.getmtime (PATH) #返回文件或目录的最后修改时间


Judge
Os.path.exists (PATH) #判断路径是否存在
Os.isabs (PATH) #判断路径是否是绝对路径
Os.isfilke (PATH) #判断文件是否存在
Os.isdir (PATH) #判断目录是否存在

Import Sys
Sys.path #返回模块的搜索路径
SYS.ARGV #获取文件传递的参数, the first one is the file name
Sys.exit (n) #退出程序
Sys.version #获取当前python解释器的版本
Sys.platform returns the operating system platform name
Sys.stdin #重定向输入
Sys.stdout #重定向输出
Sys.stderr #重定向错误

Python Basic Learning OS module and SYS module

Related Article

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.