Finding in which class an object's method comes from

Ben Finney ben+python at
Thu Feb 4 03:49:49 EST 2016

"ast" <nomail at> writes:

> Let's invoke an obj method
> obj.funct()
> funct is first looked in ClassC, then if not found
> on ClassB, then ClassA then object

If it helps: What you describe is attribute lookup, and it happens
whether or not you're going to call the attribute.

In other words, you need only invoke ‘foo.attr’ to have Python look for
attribute ‘attr’ among the class hierarchy as you describe. Calling that
attribute is a distinct operation once the attribute is found.

> But is there a command to know where funct is found ?

That's been answered, but I'm curious to know what your program will do
with that information?

 \       “But Marge, what if we chose the wrong religion? Each week we |
  `\          just make God madder and madder.” —Homer, _The Simpsons_ |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list