os.path.abspath(path)
返回绝对路径
import os
print(os.path.abspath(".")) #当前目录的绝对路径
print(os.path.abspath(r"..")) #上级目录的绝对路径
print(os.path.abspath(r"D:\python_workshop\python6\revise\函数.py"))
运行结果
D:\python_workshop\python6\selenium_webdriver
D:\python_workshop\python6
D:\python_workshop\python6\revise\函数.py