【问题标题】:get absolute path of file without filename using Python pathlib使用 Python pathlib 获取没有文件名的文件的绝对路径
【发布时间】:2020-12-14 22:32:48
【问题描述】:

我想替换file_location = os.path.abspath(os.path.dirname(__file__))pathlib 获取不带文件名的文件的绝对路径
使用directorypath = pathlib.Path(__file__).resolve() 给我绝对路径+文件名
没有文件名如何获取绝对路径?

【问题讨论】:

    标签: python-3.x directory path pathlib


    【解决方案1】:

    您可以使用'.parent': directorypath = pathlib.Path(__file__).resolve().parent
    Path.parent

    【讨论】:

      猜你喜欢
      • 2010-09-18
      • 1970-01-01
      • 2023-04-05
      • 2013-11-17
      • 2021-05-13
      • 2012-04-24
      相关资源
      最近更新 更多