How to give a custom object instance a type name ?
Kim Petersen
kp at kyborg.dk
Mon Jul 14 08:42:17 EDT 2003
Graeme Matthew wrote:
> Hi all, quick one,
>
> I hope I am explaining this properly, I am wanting to do some introspection
> on custom object instances, for example:
>
> import md5
>
>>>>m = md5.new()
>>>>type(m)
>
> <type 'md5.md5'>
>
> I can at least test here by doing something like if type(m) == 'md5.md5':
how about doing this instead:
isinstance(m,md5.md5)
>
>
> Here is a custom Dispatcher class that I have written
>
>
>>>>from BI.System.Controller.Dispatcher import Dispatcher
>>>>x = Dispatcher()
>>>>type(x)
>
> <type 'instance'>
>
> How do I get the same as with instance 'm' above where the type displays the
> actual object instance name, however my
> custom dispatcher instance is just a generic 'instance', is there some
> builtin where this is set ?
isinstance(x,Dispatcher)
otherwise if you _really_ need the name - just do as some others indicated.
--
Med Venlig Hilsen / Regards
Kim Petersen - Kyborg A/S (Udvikling)
IT - Innovationshuset
Havneparken 2
7100 Vejle
Tlf. +4576408183 || Fax. +4576408188
More information about the Python-list
mailing list