← Go Back

How to Convert a Relative Path to an Absolute Path

Using the pathlib.Path.resolve() standard method:

from pathlib import Path
# ../../file.txt is the relative path.
p = Path("../../file.txt")
# The resolve() method returns the absolute path.
# For example, C:\Users\jdoe\Documents\file.txt.
print(p.resolve())


pathlib files cwd


🐍 You might also find interesting: