I want to get the current file\'s directory path. I tried:
>>> os.path.abspath(__file__)
\'C:\\\\python27\\\\test.py\'
But how can
In Python 3.x I do:
from pathlib import Path
path = Path(__file__).parent.absolute()
Explanation:
Path(__file__) is the path to the current file..parent gives you the directory the file is in..absolute() gives you the full absolute path to it.Using pathlib is the modern way to work with paths. If you need it as a string later for some reason, just do str(path).