首页 /编程语言和算法/Python
 Python 获取当前文件的目录和路径
昨天 21:32
import os
current_dir = os.path.dirname(__file__)
print("当前文件的目录是:", current_dir)

current_path =  os.path.abspath(__file__)
print("当前文件的路径是:", current_path)

运行结果:

当前文件的目录是: d:\abc
当前文件的路径是: d:\abc\test.py


 
全部回复(0)
首页 | 电脑版 |