python: get the current directory, parent directory path

Get the current file path, parent directory, set the other methods directory

 

Import os 


Print ( " === === get the current directory " )
 # current working directory path to the script 
Print (os.getcwd ())
 # os.path.abspath () to get the absolute path 
Print (os.path.abspath (os.path.dirname ( __FILE__ ))) 

Print ( " === get the current file-level directory === " )
 Print (os.path.abspath (os.path.dirname (os.path.dirname ( __FILE__ )) ))
 Print (os.path.abspath with (os.path.dirname (The os.getcwd ())))
 Print (os.path.abspath with (the os.path.join (The os.getcwd (), " .. " )) )
 Print(os.path.dirname (os.getcwd ()))
 # os.path.join () connected directory name and file or directory 


Print ( " ==== set the path for the test_case files in the current folder parent directory === = " ) 
path = the os.path.join (os.path.dirname (The os.getcwd ()), " test_case " )
 Print (path)

 

Guess you like

Origin www.cnblogs.com/juankai/p/11580122.html