通过 __file__ 获取
os.path.dirname(os.path.realpath(__file__))
www#gaodaima.com来源gaodai#ma#com搞@@代~&码*网搞代码
通过 getcwd 获取当前路径
os.getcwd()
其它相关路径
#当前文件路径 print(os.path.realpath(__file__)) #当前文件所在的目录,即父路径 print(os.path.split(os.path.realpath(__file__))[0]) #找到父路径下的其他文件,即同级的其他文件 print(os.path.join(proDir,"config.ini"))
来源:搞代码网:原文地址:https://www.gaodaima.com