Python OS, os.path and SYS modules

Source: Internet
Author: User


OS: Provides interfaces to interact with the system

Common methods:

Os.name: Show the platform you are using

Os.system (command): Run shell command

OS.GETCWD (): View working directory

Os.chdir (d): Changing the working directory

Os.listdir (d): View all content in the specified directory

Os.remove (f): Delete the specified file

Os.chmod (F,C): Modify the permissions of the specified file, represented by four octal numbers in Linux

Os.makeirs (DN): Create a directory recursively

Os.mkdir (DN): Create directory, parent directory must exist

Os.rmdir (DN): Delete directory, only last level directory (only empty directory can be deleted)

Os.removedirs (DN): Recursively delete directory, specify last level directory to start deletion (only empty directories can be deleted)

C: Permission f: File dn: directory name


Os.path modules, and path-related modules

Common methods:

Os.path. DirName (P): Show path directory name

Os.path. BaseName (P): Show base name

Os.path. Join (D,B): Splicing directory name and base name

Os.path. Split (P): Return (d,b) tuple

Os.path. GetSize (P): Returns the file size if the file exists and returns an exception if it does not exist

Os.path. Exists (p): Determines whether the specified file exists

Os.path. Isdir (P): Determine if it exists and is a directory

Os.path. Isfile (p): Determines whether the file is present and

Os.path. Ismount (p): Determines whether a mount point

P: Path D: Path directory name B: base name


SYS: module related to Python interpreter

Common methods:

Sys.path (): View the search path for import, returned as a list

SYS.ARGV (): Returns the command line parameters, including the script name, returned as a list

Sys.exit (0): Exit program, custom exit code

sys.stdout: Standard output
Sys.stdin: Standard input
Sys.stderr: Error Output

Sys.executable: Returns the Python interpreter path





This article is from the "Automated Operations" blog, please be sure to keep this source http://hongchen99.blog.51cto.com/12534281/1910792

Python OS, os.path and SYS modules

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.