- import os
- def test1():
- test_path = os.path.dirname(os.path.abspath(__file__))
- test1_path = os.path.dirname(os.path.abspath(__file__)) + '\..'
- a_path = os.path.abspath(test_path + '\drivers\chromedriver.exe')
- b_path = os.path.abspath(test1_path + '\drivers\chromedriver.exe')
- print(test_path)
- print('a_path: %s' % a_path)
- print(test1_path)
- print('b_path: %s' % b_path)
- test1()
复制代码
多加了两句print你可能理解起来容易一些,我本人没用过这个os模块的这个方法
另外查了一下os.path模块说明如下:
FUNCTIONS
abspath(path)
Return the absolute version of a path. 这里应该就是把\..之前的一级删掉吧,同时也删掉\..