listing the type of an object

Thomas Jollans thomas at jollans.com
Wed Jun 27 17:21:34 EDT 2007


Stef Mientki wrote:
> How can I list a type of an object instance ?
> 
> I tried:
> 
> class tLED (tDevice):
>   def some_proc(self):
>     print 'type(self)', type(self)
> 
> But i gives me:
>   type(self) <type 'instance'>
> 
> 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)
> 

Ahhh, history. At the moment (that is in  2.2 <= Python Version < 3.0 ),
there are two types of classes: old-style classes are the default and a
load of WTF?, which new-style classes make sense and behave like you
(that is "one" in general and you, Stef, in particular) expect.

As I'm too lazy to explain what all this is about, I'll point you to a
page with a promising title:

http://wiki.python.org/moin/NewClassVsClassicClass

Thomas Jollans

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20070627/67aa8744/attachment.sig>


More information about the Python-list mailing list