listing the type of an object
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Jun 28 03:17:46 EDT 2007
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>
> 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()
More information about the Python-list
mailing list