编程语言
首页 > 编程语言> > python 获取文件本身的绝对路径

python 获取文件本身的绝对路径

作者:互联网

 

tester.py:

import os
print (os.path.dirname(__file__))
print (os.path.abspath(__file__))
print (os.path.abspath(os.path.dirname(__file__)))
print (os.path.dirname(os.path.abspath(__file__)))

输出

bogon:Desktop macname$ python3 tester.py 

/Users/macname/Desktop/tester.py
/Users/macname/Desktop
/Users/macname/Desktop



bogon:api_automation macname$ python3 ../../tester.py 
../..
/Users/macname/Desktop/tester.py
/Users/macname/Desktop
/Users/macname/Desktop

 

 

参考:

https://www.cnblogs.com/royfans/p/7908009.html

 

标签:__,Users,python,macname,获取,绝对路径,path,Desktop,os
来源: https://www.cnblogs.com/sea-stream/p/11395275.html