How to get absolute path of a pathlib.Path object?

后端 未结 4 1231
暗喜
暗喜 2021-02-03 16:56

Making a path object with pathlib module like:

p = pathlib.Path(\'file.txt\')

The p object will point to some file in

4条回答
  •  旧巷少年郎
    2021-02-03 17:15

    pathlib.Path.cwd() / p
    

    This is recommended by CPython core developers as the "one obvious way".

    p.resolve() does not return an absolute path for non-existing files on Windows at least.

    p.absolute() is undocumented.

提交回复
热议问题