1. 实验环境
/opt/Taobao/Selenium/demo.py
2. os
# 返回当前文件名称
print(os.path.basename(__file__))
# main.py
# 返回整体路径
print(os.path.realpath(__file__))
# /opt/Taobao/Selenium/demo.py
# 返回文件所在文件夹的绝对路径
print(os.path.dirname(os.path.realpath(__file__)))
# /opt/Taobao/Selenium/
标签:__,Python,py,Selenium,绝对路径,file,path,os
From: https://www.cnblogs.com/leoshi/p/17003141.html