Back
I want to get the current file's directory path.
I tried:
>>> os.path.abspath(__file__) 'C:\\python27\\test.py'
>>> os.path.abspath(__file__)
'C:\\python27\\test.py'
But how can I retrieve the directory's path? For example:
'C:\\python27\\'
For retrieving the directory's path in Python we will do the following way:-
from pathlib import Path mypath = Path().absolute() print(mypath)
from pathlib import Path
mypath = Path().absolute()
print(mypath)
31k questions
32.8k answers
501 comments
693 users