From here: Find current directory and file's directory
I tried in spyder (Python IDE):
dir_path = os.path.dirname(os.path.realpath('__file__'))
and:
cwd = os.getcwd()
I only get like just the user directory and not the location of my source file where I'm coding
My source code is here:
C:\Users\username\test\testerrr\test.py
I only get:
C:\Users\username
I use:
os.path.dirname(os.path.realpath('__file__'))
and not:
os.path.dirname(os.path.realpath(__file__))
else I get this:
os.path.dirname(os.path.realpath(__file__))
Traceback (most recent call last):
File "<ipython-input-18-98004a18344a>", line 1, in <module>
os.path.dirname(os.path.realpath(__file__))
NameError: name '__file__' is not defined
Well, it seems that's works only when we run its through shell.