SYS module and OS module

Source: Internet
Author: User

SYS module
sys.argv command line argument list, the first element is the programmer's ability path Sys.exit (n) exit the program, exit normally exits (0) Sys.version Gets the version information of the Python interpreter sys.maxint the largest int value ( /c0>3. 0 Cancel) Sys.path returns the search path for the module, initializes with the value of the PYTHONPATH environment variable Sys.platform returns the name of the operating system platform Sys.stdout output related content Sys.stdin input SYS.S Tdout plus time can write a progress bar of hundred percent forIinchRange (100):      #num + = "#"Sys.stdout.write ('\ r')##意思是打印在清空I1 = i/100Sys.stdout.write ("%s%% |%s"% (int (i1 *), int (I1 *100) *"#") ) Sys.stdout.flush () Time.sleep (0.3)

Case:

SYS combined with the OS, add the current path, or the required path to the module search path

    Import SYS       Import OS       = Os.path.dirname (__file__)      'bin'      =  Os.path.join (A, B)      sys.path.append (      c)print(Sys.path)  

OS Module
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, equivalent to the shell under the CD Os.curdir returns the current directory (".") Os.pardir Gets the parent directory string name of the current directory ("..") Os.makedir Os.makedirs ('Dir1/dir2') to generate multiple recursive directories os.removedirs ('dirname1'If the directory is empty, it is deleted and recursively to the previous level directory, if it is also empty, then delete, and so on Os.mkdir ('dirname') to generate a single-level directory, equivalent to the shell mkdir dirname os.rmdir ('dirname'Delete the single-level empty directory, if the directory is not empty can not be deleted, error, equivalent to the shell of the rmdir dirname Os.listdir ('dirname'lists all files and subdirectories under the specified directory, including hidden files, and prints a list of os.remove () deletes a file Os.rename ("oldname","New") Rename File/Catalog Os.stat ('Path/filename') Get File/directory information Os.seq operating system-specific path delimiter, win inferior"\\", Linux inferior"/"os.pathseq The string Os.name string used to split the file path indicates the current usage platform. Win-'NT';linux->'POSIX'Os.system ("Bash Command"run the shell command and directly display the Os.environ get environment variable Os.path.abspath (PATH) returns path normalized absolute path Os.path.split (path) returns the path partition and the file name of the two tuple OS.P Ath.dirname (path) returns the directory of path. In fact, the first element of Os.path.split (path) os.path.basename returns the last file name of path. If Path takes/or \ End, then a null value is returned. The second element of Os.path.split (path), os.path.exists (path), returns True if path exists, or false if path does not exist Os.path.isabs (path) If path is an absolute path, Returns True Os.path.isfile (path) If path is an existing file that returns TRUE. Otherwise, false Os.path.isdir (path) returns True if path is an existing directory. Otherwise, false Os.path.join (path1[,path2[,...]]) is returned after combining multiple paths, and parameters before the first absolute path are ignored os.path.getatime (path) Returns the last access time of the file or directory to which path is pointing os.path.getmtime (path) returns the last modified time of the file or directory to which the path points1), os.sep change the path delimiter in the operating system. 2), OS.GETCWD () Gets the current path, which is more commonly used in Python code. 3), Os.listdir () lists all files and folders in the current directory. 4), Os.remove () method to delete the specified file. 5), the Os.system () method is used to run the shell command. 6), Os.chdir () change the current directory to the specified directory.

SYS module and OS module

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.