Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (33.1k points)

I want to get the current file's directory path.

I tried:

>>> os.path.abspath(__file__)

 'C:\\python27\\test.py'

But how can I retrieve the directory's path? For example:

'C:\\python27\\'

1 Answer

0 votes
by (106k points)

For retrieving the directory's path in Python we will do the following way:-

from pathlib import Path 

mypath = Path().absolute() 

print(mypath)

image

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
+1 vote
2 answers
asked May 30, 2019 in Python by Ritik (3.5k points)
0 votes
1 answer

Browse Categories

...