Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 6
    Very helpful. Using os.path.abspath() gave me an error: AttributeError: 'NoneType' object has no attribute 'startswith', using Path().resolve() does not with the same relative filepath. (Linux and Python3.4) Commented Aug 31, 2015 at 16:14
  • 4
    According to my experiment, in window platform, resolve() returns full path to you only if it is able to resolve() file. But, os.path.abspath returns full path to you anyway even the file does not exists. However, in linux, it always return absolute path Commented Jul 31, 2020 at 9:04
  • Why is that when the Path(__file__) alone (without the resolve method) is used in a module being imported along with a package, gives the absolute path instead of the relative path? Commented Aug 8, 2020 at 8:50
  • 1
    Note that resolve() will follow symlinks. If you don't want this, use absolute() instead, which will leave not resolve symlinks. Commented Aug 18, 2021 at 16:09
  • 1
    If one wants to stay with the legacy os.path library, one can also use os.path.realpath(PATH) to get the same functionality as pathlib.Path(PATH).resolve(). Especially, realpath() also follows symlinks. Commented Mar 24, 2024 at 0:40