The-os of the Python module

Source: Internet
Author: User
Tags python script

Python OS module

Import OS

OS.GETCWD () # The path to the working directory where the Python script is located

Os.chdir (R '/tmp ') # switch directory to TMP

Os.makedirs (R '/a/b/c ') # Create a multi-tiered folder

Os.removedirs (R '/a/b/c ') #删除多层文件夹

Os.mkdir ('/A ') # Create a single folder

Os.listdir (' home ') # List all folders and files

Os.rename (' A ', ' B ') # Modify file names for folders and files

Os.stat (R '/tmp/ans.log ') # file for some time information

OS.SEP # Slash/

Os.linesep #换行符 \ n

OS.PATHSEP # Path delimiter

Os.name # Current system designator win--> ' NT ' linux--> ' POSIX '

Os.system (' ls ') # shell command to run Linux

Os.environ # Display System variables

Os.path.abspath ('. ') # Show absolute path to a relative path

Os.path.split ('/tmp/ans.log ') # splits the path and file name ('/tmp ', ' Ansible.log ')

Os.path.dirname (' Ans.log ') # Lists the folder where the files are located

Os.path.basename ('/tmp/ans.log ') # Remove path only shows file name

Os.path.exists ('/tmp ') # path exists If True does not exist false

Os.path.isabs ('/tmp ') # Whether the path is an absolute path is true no false

Os.path.isfile ('/tmp/ans.log ') # path exists If file is true no false

Os.path.isdir ('/tmp ') # Path exists If folder is True no false

Os.path.join ('/tmp ', ' Ans.log ') #多个路径文件名组合成一个字符串

Os.path.getatime ('/tmp ') # Gets the last access time of the file or folder

Os.path.getmtime ('/tmp ') # Gets the last modified time of the file or folder

The-os of the Python 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.