[FRPythoneers] instance question

Mike Olson Mike.Olson at fourthought.com
Sun Mar 17 21:26:39 MST 2002


On Sun, 2002-03-17 at 18:53, Karl Putland wrote:
> 
> Right, but with the newer Pythons,
> 
> if   A-->B-->C
> and  B-->D
> and  C-->D

Only if you have

D-->object

and only in 2.2+

If you don't inherit from object then it has not changed.

Mike

> 
> Then
> 
>     A
>    / \
>   B   C
>    \ /
>     D
> 
> Now if D implements my_func() and C overrides my_func()
> in 1.5.2, The search order would be
> A,B,D,C,D
> and my_func() would be found in D first.
> In the newer Pythons, the search would go
> A,B,C,D
> and my_func() would be would be found in C.
> 
> So the recursive function that you defined
> would return the Classes in the old style
> search order but would not be appropriate
> for newer Pythons.
> 
> --Karl
> 
> 
> --- Mike Olson <Mike.Olson at fourthought.com> wrote:
> > On Sun, 2002-03-17 at 11:47, Mike Olson wrote:
> > > 
> > > The search order in the above is:
> > > E, C, A, B, D
> > 
> > I should clarify just to be sure.  The actual search order is
> > 
> > inst.__dict__,E, C,A,B,D
> > 
> > Mike
> > 
> > > 
> > > >>> def Flatten(klass):
> > > ...   instance = [klass]
> > > ...   for sub in klass.__bases__:
> > > ...     instance.extend(Flatten(sub))
> > > ...   return instance
> > > ...
> > > >>> print Flatten(inst.__class__)
> > > [<class __main__.E at 0x816da44>, <class __main__.C at
> > 0x816df4c>,
> > > <class __main__.A at 0x816d17c>, <class __main__.B at
> > 0x816d344>, <class
> > > __main__.D at 0x816e1ac>]
> > > 
> > > 
> > > Mike
> > > 
> > > > 
> > > > --Karl
> > > > 
> > > > --- Mike Olson <Mike.Olson at fourthought.com> wrote:
> > > > > On Sun, 2002-03-17 at 10:39, Evelyn Mitchell wrote:
> > > > > > I know you can use isinstance(object, class) to find out
> > if
> > > > > object is an
> > > > > > instance of class (or of a subclass of class).
> > > > > > 
> > > > > > Is there any way to find out all the classes that object
> > may be
> > > > > an instance
> > > > > > of?
> > > > > > 
> > > > > > Bicycle Repair is streching me again.
> > > > > 
> > > > > You would need to walk the tree by hand, or write a quick
> > routine
> > > > > to
> > > > > flatten it.  I don't know of anything builtin
> > > > > 
> > > > > def Flatten(klass):
> > > > >     instances = []
> > > > >     for sub in klass.__bases__:
> > > > >         instances.append(sub)
> > > > >         instances.extend(Flatten(sub))
> > > > >     return instances
> > > > > 
> > > > > print Flatten(inst)
> > > > > 
> > > > > Mike
> > > > > 
> > > > > > 
> > > > > > -- 
> > > > > > Regards,                    tummy.com, ltd 
> > > > > > Evelyn Mitchell             Linux Consulting since 1995
> > > > > > efm at tummy.com               Senior System and Network
> > > > > Administrators
> > > > > >                             http://www.tummy.com/
> > > > > > _______________________________________________
> > > > > > This message sent by the FRPythoneers mailing list.
> > > > > > Unsubscribe: echo unsubscribe |
> > > > > FRPythoneers-request at lists.community.tummy.com
> > > > > > URL:
> > > > >
> > http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> > > > > -- 
> > > > > Mike Olson                                Principal
> > Consultant
> > > > > mike.olson at fourthought.com                +1 303 583 9900 x
> > 102
> > > > > Fourthought, Inc.                        
> > http://Fourthought.com 
> > > > > 4735 East Walnut St,                      http://4Suite.org
> > > > > Boulder, CO 80301-2537, USA
> > > > > XML strategy, XML tools, knowledge management
> > > > > 
> > > > > _______________________________________________
> > > > > This message sent by the FRPythoneers mailing list.
> > > > > Unsubscribe: echo unsubscribe |
> > > > > FRPythoneers-request at lists.community.tummy.com
> > > > > URL:
> > > >
> > http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> > > > 
> > > > 
> > > > __________________________________________________
> > > > Do You Yahoo!?
> > > > Yahoo! Sports - live college hoops coverage
> > > > http://sports.yahoo.com/
> > > > _______________________________________________
> > > > This message sent by the FRPythoneers mailing list.
> > > > Unsubscribe: echo unsubscribe |
> > FRPythoneers-request at lists.community.tummy.com
> > > > URL:
> > http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> > > -- 
> > > Mike Olson                                Principal Consultant
> > > mike.olson at fourthought.com                +1 303 583 9900 x 102
> > > Fourthought, Inc.                        
> > http://Fourthought.com 
> > > 4735 East Walnut St,                      http://4Suite.org
> > > Boulder, CO 80301-2537, USA
> > > XML strategy, XML tools, knowledge management
> > > 
> > > _______________________________________________
> > > This message sent by the FRPythoneers mailing list.
> > > Unsubscribe: echo unsubscribe |
> > FRPythoneers-request at lists.community.tummy.com
> > > URL:
> > http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> > -- 
> > Mike Olson                                Principal Consultant
> > mike.olson at fourthought.com                +1 303 583 9900 x 102
> > Fourthought, Inc.                         http://Fourthought.com 
> > 4735 East Walnut St,                      http://4Suite.org
> > Boulder, CO 80301-2537, USA
> > XML strategy, XML tools, knowledge management
> > 
> > _______________________________________________
> > This message sent by the FRPythoneers mailing list.
> > Unsubscribe: echo unsubscribe |
> > FRPythoneers-request at lists.community.tummy.com
> > URL:
> http://lists.community.tummy.com/mailman/listinfo/frpythoneers
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - live college hoops coverage
> http://sports.yahoo.com/
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
-- 
Mike Olson                                Principal Consultant
mike.olson at fourthought.com                +1 303 583 9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
4735 East Walnut St,                      http://4Suite.org
Boulder, CO 80301-2537, USA
XML strategy, XML tools, knowledge management




More information about the FRPythoneers mailing list