This question already has an answer here:
-
*
/questions/3718657/how-to-properly-determine-current-script-directory-in-python
/questions/3718657/how-to-properly-determine-current-script-directory-in-python
9 answers
Answers
You need to call os.path.realpath on __file__, so that when __file__ is a filename without the path you still get the dir path:
import os print(os.path.dirname(os.path.realpath(__file__)))
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/4934806/how-can-i-find-scripts-directory-with-python