Although there are some related threads according to find the source file of a python module, I did not find an answer on how to get the filename from within a python class in a most simple and reliable way. For a hypothetical file located at /usr/local/TestLib.py:
class MyTest(object):
def __init__(self):
myLocation = XXX
I want the variable myLocation to contain the string /usr/local/TestLib.py. __file__ does not seem to work inside my class.
How should I do that?
__file__works anywhere within module, be that inside a class or outside.