Code python

Python Convert Relative to Absolute File Path

Kontext Kontext visibility 3,926 comment 0 access_time 2 years ago language English

descriptionCode description

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
fork_rightFork
more_vert
copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts