On Thu, Feb 4, 2016 at 7:25 PM, ast <nom...@invalid.com> wrote:
> Hi
>
> Suppose we have:
>
> ClassC inherit from ClassB
> ClassB inherit from ClassA
> ClassA inherit from object
>
> Let's build an object:
>
> obj = ClassC()
>
> Let's invoke an obj method
>
> obj.funct()
>
> funct is first looked in ClassC, then if not found
> on ClassB, then ClassA then object
>
> But is there a command to know where funct is
> found ?

You can see that by looking at the objects without calling them:

>>> class A:
...  def a(self): pass
...
>>> class B(A):
...  def b(self): pass
...
>>> class C(B):
...  def c(self): pass
...
>>> obj = C()
>>> obj.a
<bound method A.a of <__main__.C object at 0x7fb7bdfa57f0>>
>>> obj.b
<bound method B.b of <__main__.C object at 0x7fb7bdfa57f0>>
>>> obj.c
<bound method C.c of <__main__.C object at 0x7fb7bdfa57f0>>

The information comes from the function's qualname:

>>> obj.c.__func__.__qualname__
'C.c'

Is that what you're hoping for?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to