目录结构

pyhton之os.path

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)所在脚本是以绝对路径运行的,则会输出该脚本所在的绝对路径,若以相对路径运行,输出空目录
pyhton之os.path

os.path.abspath(file)

获取当前文件的绝对路径,无论脚本是以绝对路径运行还是以相对路径运行
pyhton之os.path

相关文章:

  • 2021-12-27
  • 2021-08-15
  • 2021-10-29
  • 2022-12-23
  • 2022-03-05
  • 2021-08-04
  • 2021-05-09
  • 2022-12-23
猜你喜欢
  • 2021-09-23
  • 2021-11-24
  • 2022-01-19
  • 2021-10-19
  • 2022-12-23
  • 2021-09-29
  • 2019-11-22
相关资源
相似解决方案