listing the type of an object

Bruno Desthuilliers bruno.42.desthuilliers at
Thu Jun 28 09:17:46 CEST 2007

Stef Mientki a écrit :
> How can I list a type of an object instance ?
> I tried:
> class tLED (tDevice):

Do yourself (and the world) a favour and give up hungarian notation... 
This should be:

class Led(Device):


>   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):

led = Led()

More information about the Python-list mailing list