查看: 3  |  回复: 0
  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


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com