Notes The python os, sys module

First a quick look at the definition of python module, the module is a file containing functions and variables that you have defined to .py suffix. A python file is a module, the module functions into easy code maintenance and management, in addition to also avoid the same function name or variable name conflicts. Modules currently three main types: built-in standard modules, third-party modules, custom library modules. This segment of the os, sys module is a built-in standard modules.

1, os library system is mainly used for processing files and directories, the following libraries for common use.

. 1  Import os
 2  
. 3  Print (os. __All__ is )   # See methods at all os module 
. 4  
. 5  Print (The os.getcwd ()) # Get the current path 
. 6  
. 7  Print (os.path.dirname ( __FILE__ ))   # get the currently executed module path 
. 8  
. 9  Print (os.path.abspath with (The os.getcwd ())) # returns the absolute path 
10  
. 11  Print (the os.path.join (The os.getcwd (), ' lj.py ' )) # directory splice 
12  Print (os.path.split ( "D: \\ \\ bk6.py untitled3 pycharmwokspace \\ " )) # catalog division, into the path of the basename and dirname, returns a tuple 
13 is  
14  for Item in the os.listdir (The os.getcwd ()): # Get all folders and files in the directory 
15      Print (Item)
 16  
. 17  
18 is  Print (the os.path.isfile (the os.getcwd ())) # determines whether or not the current path for the file 
. 19  Print (os.path.isdir (the os.getcwd ( ))) # determines whether the current directory path 
20 is  
21 is  Print (os.path.exists (the os.path.join (The os.getcwd (), ' lj.py ' ))) # determines whether there is a current directory 
22 is  
23 is Print (os.path.getatime ( ' D: \\ pycharmwokspace untitled3 \\ \\ bk6.py ' )) # Gets last access time 
24-  Print (os.path.getmtime ( ' D: \\ pycharmwokspace \\ \\ untitled3 bk6.py ' )) # Gets the last modified time

2, sys library mainly used to provide maintenance to the python interpreter variables, such as the maintenance of an environment variable

1  Import   SYS
 2  
3 directional sys.exit () # script termination
4  Print (sys.path) # View interpreter search path  5  6  Print (sys.version) # View python version  7  Print (sys.platform) # View the current system name

Guess you like

Origin www.cnblogs.com/heertong/p/12150709.html