python自動化接口測試裏面經常用到的兩個os.path方法
os.path.split(path ) : 把路徑分割成 dirname(路徑名) 和 basename(文件名),返回一個元組;
os.path.realpath(path):獲取path的絕對路徑;
os.path.realpath(__file__):獲取realpath方法所在腳本的絕對路徑
舉例如下:
path = os.path.split(os.path.realpath(__file__))[0]
這裏os.path.realpath(__file__) 返回當前腳本的絕對路徑(比如是C:/users/automation/test.py);
os.path.split( ):將上面得到的絕對路徑進行分割得到一個元組['C:/users/automation/', 'test.py']
在後面加上一個[0],即得到了‘C:/users/automation/’