python-文件路径

import os.path

#返回目录路径
print(os.path.dirname(__file__))
#返回绝对路径
print(os.path.abspath(__file__))
#判断文件是否存在
print(os.path.exists('test.txt'))

posted on 2022-03-15 16:00  阿躺  阅读(39)  评论(0)    收藏  举报