pyhton之os.path
时间:2018-08-19 13:26:25
收藏:0
阅读:149
目录结构
file
__file__表示了当前文件的path
以相对路径运行:python 1.py
结果:1.py
以绝对路径运行:python F:\python-study\test\1.py
结果:F:\python-study\test\1.py
os.path.dirname(path)
去掉文件名,返回目录,若print os.path.dirname(file)所在脚本是以绝对路径运行的,则会输出该脚本所在的绝对路径,若以相对路径运行,输出空目录
os.path.abspath(file)
获取当前文件的绝对路径,无论脚本是以绝对路径运行还是以相对路径运行
原文:https://www.cnblogs.com/raind/p/9500997.html
评论(0)