To get the path to the directory where the Python file is stored write the code below in that file:
directory_path = os.path.dirname(os.path.realpath(__file__))
The above code may fail if you have already used os.chdir() to change the working of your current directory because the value of _file_ constant is relative with the current working directory and does not change by an os.chdir() call.
If you want to get the current working directory use the following code:
cw_d = os.getcwd()
Here, os.getcwd() returns a string representing the current working directory.
Hope it helps!