Python OS module and SYS module

Source: Internet
Author: User
Tags python script

1. OS module: Provides an interface for invoking the operating system

OS.GETCWD ()   Gets the current working directory, which is the directory path of the current Python script work os.chdir ("DirName")    changes the current script working directory, which is equivalent to the shell Cdos.curdir    return current directory:  ('. ') os.pardir   Gets the parent directory string name of the current directory: (' ... ') Os.makedirs (' dirname1/dirname2 ')      can generate multi-level recursive directory Os.removedirs (' dirname1 ')       If the directory is empty, then delete, and recursively to the previous level of the directory, if also empty, then delete, and so on Os.mkdir (' dirname ')      generate a single-level directory, equivalent to the shell mkdir  Dirnameos.rmdir (' dirname ')      Delete single-level empty directory, if the directory is not empty can not be deleted, error; equivalent to Rmdir dirnameos.listdir in the shell (' dirname ')      list all files and subdirectories under the specified directory, including hidden files, and print os.remove ()    Delete a file Os.rename (" Oldname "," NewName ")    Rename File/directory Os.stat (' path/filename ')    get File/directory information os.sep      Output operating system-specific path delimiter, win under "\ \", Linux for "/" os.linesep     output the current platform using the line terminator, win under "\t\n", Linux "\ N "os.pathsep     output is used to split the file path of the string  win under; Linux is:os.name     The output string indicates the current usage platform. Win-> ' nt '; linux-> ' POSIX ' Os.system ("bash&nBsp;command ")    run the shell command, directly display Os.popen (" Bash command). "Read ()    run shell command, Get execution results os.environ   get system environment variable Os.pathos.path.abspath (path)   Return path normalized absolute path  os.path.split (path)   Split path into directory and file name two tuples return  os.path.dirname (path)   directory to return path. It is actually the first element of Os.path.split (path)   Returns the last file name of path. If path ends with a/or \, then a null value is returned.                           the second element of Os.path.split (path) os.path.exists    If path exists, returns true If path does not exist, return Falseos.path.isabs (path)    If path is an absolute path, return Trueos.path.isfile (path)    Returns true if path is a file that exists. Otherwise, return Falseos.path.isdir (path)    True if path is an existing directory. Otherwise return Falseos.path.join (path1[, path2[,  ...])    returns a combination of multiple paths, the parameters before the first absolute path are ignored Os.path.getatime (path)    Returns the last access time of the file or directory pointed to by Path Os.path.getmtime (path)    returns the last modified time of the file or directory to which path is pointing os.path.getsize (path)  Returns the size of path 


2. SYS module is an interface that interacts with the Python interpreter

SYS.ARGV command line argument list, the first element is the program itself path Sys.exit (n) exit the program, exit normally exits (0), error exits Sys.exit (1) sys.version get python explanation Version information of the program Sys.path returns the search path for the module, using the value of the PYTHONPATH environment variable when initializing Sys.platform returns the operating system platform name



This article from

Https://www.cnblogs.com/weihengblog/p/8505986.html

Python 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.