Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...