Bug or wart? You make the call.

Just just at xs4all.nl
Sat Mar 8 14:20:25 EST 2003


In article <mailman.1047149535.19141.python-list at python.org>,
 Thomas Wouters <thomas at xs4all.net> wrote:

> On Sat, Mar 08, 2003 at 10:39:28AM -0800, Jeremy Fincher wrote:
> > Jp Calderone <exarkun at intarweb.us> wrote in message 
> > news:<mailman.1047068354.22570.python-list at python.org>...
> > >   There is one very practical reason.  Method objects (not "class 
> > >   methods" -
> > > those are something else) are created anew every time they are fetched!
> 
> > What's the rationale behind this behavior?
> 
> It doesn't have an official rationale, but it's easily considered. Python is
> a very dynamic language. An instance's __class__ and a class's __bases__ can
> be dynamically changed. It is part of how Python Works.

More importantly: a (bound) method has a reference to the instance, so 
is specific to that particular instance. _Not_ creating them on the fly 
means storing them in the instance, which has two disadvantages: 1) 
extra storage space needed in the instance, 2) causes a curcular 
reference (inst -> bound method -> instance).

Just




More information about the Python-list mailing list