os module and module sys

A, os common method

Import os
 Print (os. getcwd () )      # Get the current working directory 
os.chdir (r ' C: \ the User ' )    # change the working directory plus s because there are special characters, unescaping 
Print (os.curdir ())      # current directory 
Print (os.purdir ())      # parent directory 

os. makedirs ()           # create multiple folders 
os. makedev ()            # create a folder 
os. removedirs ()         # Specifies to delete a directory, delete recursively until not empty 

os. mkdir ( ' name.txt ' )    # create a file 
os. rmdir ()             # Delete empty directories, you can not remove is not empty 
Print (os.list (r ' C: \ the User ' )) 
the os.stat ( ' filename ' ) 
os.sep             # cross-platform use, specify the output path separator 
os. name           # the current platform, win-nt or LIN- 
os.system ( " dir " ) 
os. isfile ()          # determine whether a file exists 
os. isdir ()           # judge folder exists

Two, sys module common method

# SYS module 
# the sys.argv List command line arguments, the first element of the program itself path 
# the sys.exit (n-)         to exit the program, when the normal exit exit (0), an error exit sys.exit (1), an abnormality processing 
# sys.version get Python interpreter version information, inaccurate 
# sys.path            return the module search path, use the PYTHONPATH environment variable initialization value 
# sys.modules containing imported module names are first in each import here check whether they have imported modules

Third, the reference

https://www.cnblogs.com/Eva-J/articles/7228075.html

Guess you like

Origin www.cnblogs.com/lowislucifer/p/11332328.html