Configurable path to solve the problem excel

Code to get on someone else's computer after written, you can not run. This is because the change in the reference, in other words, the path has changed. We want to write a method to obtain targeted path:

Import OS 


DEF get_path ():
     '' ' Get excel path, the file path may be configured to achieve ' '' 
    project_path = The os.path.split (The os.path.split (the os.path.realpath ( __FILE__ )) [0]) [ 0]    # get the project directory 
    test_case_path = os.path.join (project_path, ' TEST_DATA ' , ' datatable.xlsx ' )
     return test_case_path 

Print (get_path ())

 

Guess you like

Origin www.cnblogs.com/xiamaojjie/p/11871001.html