0 votes
1 view
in Python by (33.2k 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 (107k 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.8k 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 !


Categories

...