__FILE__ equivalent in Python; get the path to current file in Python
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
Permalink for __FILE__ equivalent in Python; get the path to current file in Python


Adam Gomaa said,
November 25, 2008 @ 2:11 pm
It’s __file__ in Python.
Codehead said,
November 25, 2008 @ 2:20 pm
Hey, I know now, it’s very silly but I was searching for it and this was what I found!
nancy said,
January 5, 2009 @ 8:22 pm
The problem with __file__ is that it doesn’t always work. Using the inspect module is more robust.
Codehead said,
January 5, 2009 @ 8:37 pm
Hey, thanks for the info, it would be nice if you could explain this a little more though. Thanks!