[FRPythoneers] instance question

Jim Vickroy Jim.Vickroy at noaa.gov
Mon Mar 18 09:25:04 MST 2002


Evelyn,

If you are using Python 2.2, method resolution order may be of use:

>>> class spam(object): pass
...
>>> classes = spam.mro()
>>> classes
[<class '__main__.spam'>, <type 'object'>]
>>> z = classes[0]()
>>> isinstance(z, spam)
1
>>> isinstance(z, object)
1
>>> z = classes[1]
>>> isinstance(z, object)
1
>>> isinstance(z, spam)
0
>>>

I'm just starting to use Python 2.2 and I really like it.


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.
>
> --
> 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




More information about the FRPythoneers mailing list