[FRPythoneers] instance question

Mike Olson Mike.Olson at fourthought.com
Sun Mar 17 11:55:37 MST 2002


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




More information about the FRPythoneers mailing list