[Tutor] inquire

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 15 Jan 2001 14:56:11 -0800 (PST)


On Mon, 15 Jan 2001, XIA Xiao-Qin wrote:

> 2. Can a method know the name of the class in which the method is defined?

Hmmm....  I'm certain that this is not what you wanted:

class A:
    def fun(self): print "A"
class B(A):
    def fun(self): print "B"
class C(B):
    def fun(self): print "C"
...

That's one way I can see of working with the inheritance to get the
classname where the method's declared.  But this is exactly
"A.fun.im_class.__name__" in a different disguise.  Sorry, nothing else
comes to mind at the moment.