Update:
There is __file__ in Python.
You could do this as suggested by some but I don’t know why:
import inspect this_file = inspect.currentframe().f_code.co_filename
I hope this helps
Update:
There is __file__ in Python.
You could do this as suggested by some but I don’t know why:
import inspect this_file = inspect.currentframe().f_code.co_filename
I hope this helps
It’s __file__ in Python.
Comment
Hey, I know now, it’s very silly but I was searching for it and this was what I found!
Comment
The problem with __file__ is that it doesn’t always work. Using the inspect module is more robust.
Comment
Hey, thanks for the info, it would be nice if you could explain this a little more though. Thanks!
Comment
Thanks you man it made my evening. I come from PHP.
Comment
cool, thanks for the tip
Comment
__file__ doesn’t work in the case when you start the
python script with execfile(path_to_script).
Here you get: NameError: name ‘__file__’ is not defined! (Python Version 2.6.2)
I agree, inspect is more robust.
Comment