This code snippet shows you how to convert a relative path to absolute path using os
module in Python and vice versa.
We utilize os.path.abspath
and os.path.relpath
functions. For the later, it accepts the second parameter as the base path which will be used to calculate the relative path.
Output:
*The current directory when running this code is C:\Users\userid.
C:\Users\test.csv
..\test.csv