Should Python documentation for __class__ be improved?

Stefan Franke spamfranke at bigfoot.de
Wed Mar 15 02:38:03 CET 2000


On Tue, 14 Mar 2000 18:28:51 -0500, Tom Funk
<_spam_sux_tdfunk at _spam_sux_nettally.com> wrote:

>  o  when called it creates a new instance of the class  
>     i.e., 
>
>         c=Class(arg,...) 
>
>      is the same as 
>
>         c=self.__class__(arg,...)
>
>(Pretty cool stuff, Guido! :-)

Hmm, is this case, yes, but not generally: 

  c=self.__class__(arg,...)

creates an instance of self's class even in derived classes,
(descendants of 'Class') whereas 

  c=Class(arg,...) 

creates only instances of 'Class' itself. This trick makes Guido's
implementation even a bit cooler than you'd figured out by now..

>So, what __class__ *really* is, is: 

a reference to a *class object*, which is a first order object like
integers, strings and functions too. That means they can be assigned
or passed as parameters/return values or computed by an expression
like any other value in Python.

Regards,
Stefan




More information about the Python-list mailing list