Python Example | Get the Absolute Path of a File

This python example code will show us how to get the absolute path of a file in python.

from pathlib import Path

>>> file = Path('archive/demo.txt')
>>> file
archive\demo.txt
>>> file.resolve()
C:\Users\me\study\archive\demo.txt

We can use Path.resolve() function to get the absolute path of a file.