← Go Back
How to Convert a Relative Path to an Absolute Path
Using thepathlib.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())
🐍 You might also find interesting: