python中获取路径的几种方法

import os
import sys

print(os.getcwd())    # 返回当前工作目录
print(os.path.dirname(__file__))  # 返回path目录
script_path = sys.argv[0] # 文件全路径 print(os.path.dirname(script_path)) #返回path目录 print(os.apth.basename(script_path)) # 返回文件名

print(__file__)   # 返回脚本全路径

 

posted @ 2021-12-08 20:54  宇宙刘  阅读(431)  评论(0)    收藏  举报