grandparent method with super

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Apr 5 23:49:29 CEST 2007


En Thu, 05 Apr 2007 18:13:06 -0300, Martin Manns <mmanns at gmx.de> escribió:

> On Thu, 5 Apr 2007 16:55:38 -0400
> "John Clark" <clajo04 at mac.com> wrote:

>> Because the MRO isn't just a depth first traversal, the term "first
>> grandparent" gets tricky to define...
>
> Not really. The first grandparent would be the first occurrence in the
> list from left to right, which satisfies the requirement that its
> shortest path to the current class is 2.
> The only problem: How do I get it?

Calling super() twice? F.mro()[1]? But really I don't think it's a good  
idea - depending on the *other* classes in your hierarchy, what you call  
"grandparent" may be almost anyone.
If you *have* to bypass your parent, it feels like there is something  
wrong in the class hierarchy.

-- 
Gabriel Genellina




More information about the Python-list mailing list