to pass self or not to pass self
lie.1296 at gmail.com
Wed Mar 17 14:16:53 CET 2010
On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote:
> Patrick Maupin a écrit :
>> On Mar 16, 1:59 pm, Jason Tackaberry <t... at urandom.ca> wrote:
>>> Why not create the bound methods at instantiation time, rather than
>>> using the descriptor protocol which has the overhead of creating a new
>>> bound method each time the method attribute is accessed?
>> Well, for one thing, Python classes are open. They can be added to at
>> any time. For another thing, you might not ever use most of the
>> methods of an instance, so it would be a huge waste to create those.
> A possible optimization would be a simple memoization on first access.
But what if, for example, one uses some descriptor/metaclass magic to
make it so that each subsequent access to the attribute returns a method
bound to different objects?
More information about the Python-list