os path problem

Import os 

under linux
example: I am now in /home/settings.py file

# gets the current absolute path
os.path.abspath (__ file__) # acquired content / Home / settings.py
# Get the current path of the parent directory 
os.path.dirname (os.path.abspath (__ file__))
or
os.getcwd ()
# get the contents of / home
Under window 
For example: I am in F: \ Futbin under \ settings.py file 

# gets the current absolute path 
os.path.abspath ( __FILE__ )   # content acquisition of F: \ Futbin \ settings.py 
 
# Get the current path on a level directory 

os.path.dirname (os.path.abspath ( __FILE__ )) 
or 
os.getcwd () 
# get the contents of F: \ Futbin 

or 
os.path.dirname ( __FILE__ )   # can only be so used in windows, in Print out of the linux 
# acquired content F: / Futbin

 

 

Guess you like

Origin www.cnblogs.com/smile-tree/p/11956886.html