to pass self or not to pass self

Lie Ryan lie.1296 at gmail.com
Wed Mar 17 00:57:17 EDT 2010


On 03/17/2010 05:59 AM, Jason Tackaberry wrote:
> On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote:
>> Answer here:
>>
>> http://wiki.python.org/moin/FromFunctionToMethod
> 
> I have a sense I used to know this once upon a time, but the question
> came to my mind (possibly again) and I couldn't think of an answer:
> 
> 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?

Because people wanted it like so. There was once, a time when python
doesn't have the descriptor protocol (old-style classes) and many people
feels that a high-level language like python should provide some
additional hooks for customizing attribute access which the existing
solutions like __getattr__ and __setattr__ couldn't easily provide. The
result is new-style class. Most people probably would never need to use
descriptor protocol directly, since the immediate benefit of descriptor
protocol are property(), classmethod(), and instancemethod() decorators
which, without descriptor protocol, would never become a possibility.



More information about the Python-list mailing list