Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (19k points)

Given a path such as "mydir/myfile.txt", how do I find the file's absolute path relative to the current working directory in Python? E.g. on Windows, I might end up with:


1 Answer

0 votes
by (106k points)

There are many ways to get the file Path in Python some are as follows:-

  • You can import os library to use the method os.path.abspath() and paste the directory/file name.

 import os


  • You can use library pathlib to get an absolute path in Python :

from pathlib import Path 

p = Path("pythonw.exe").resolve() 


Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2019 in Java by Ritik (3.5k points)

Browse Categories