listing the type of an object

stef s.mientki at id.umcn.nl
Thu Jun 28 04:43:09 EDT 2007


Bruno Desthuilliers wrote:
> Stef Mientki a écrit :
>> How can I list a type of an object instance ?
>>
>> I tried:
>>
>> class tLED (tDevice):
>
> <ot>
> Do yourself (and the world) a favour and give up hungarian notation... 
> This should be:
>
> class Led(Device):
>    #...
>
> </ot>
Didn't know that this was called "Hungarian notation",
and although it's not my personal favorite, it is thé standard in Delphi,
but I admit that it's not a very good choice in a object oriented 
language like Python.

The program I'm writing now is might be an exception,
I'm writing a program that should be extended by non-Python-programmers,
even maybe non-programmers !
So I'm trying to use a simplest approach from the viewpoint of the end 
users.
>
>>   def some_proc(self):
>>     print 'type(self)', type(self)
>>
>> But i gives me:
>>   type(self) <type 'instance'>
>
> looks like Device is an old style class.
>
>> Moreover, I want even the type to be listed by it's ancestor, like this
>>
>> class tDevice:
>>   def some_other_proc:
>>     print 'type(self)', type(self)
>
> Try this:
>
> class Device(object):
>   def some_other_proc(self):
>     print self, type(self)
>
> class Led(Device):
>   pass
>
> led = Led()
> led.some_other_proc()
thanks Bruno,
that does the job.

cheer,
Stef Mientki



More information about the Python-list mailing list