How do I get the current file, current class, and current method with Python? How do I get the current file, current class, and current method with Python? python python

How do I get the current file, current class, and current method with Python?


Here is an example of each:

from inspect import stackclass Foo:    def __init__(self):        print __file__        print self.__class__.__name__        print stack()[0][3]f = Foo()


import sysclass A:    def __init__(self):        print __file__        print self.__class__.__name__        print sys._getframe().f_code.co_namea = A()