status of foo.__get__ ?

Bengt Richter bokr at oz.net
Tue May 27 05:20:41 EDT 2003


On Tue, 27 May 2003 14:41:22 +1200, "Greg Ewing (using news.cis.dfn.de)" <g2h5dqi002 at sneakemail.com> wrote:

>Bengt Richter wrote:
>> For python 2.2.2 at least, it appears that one can create a
>> sort of "bound function" analogous to bound methods from an ordinary function, e.g.,
>> 
>>  >>> def foo(x,y):
>>  ...     print 'foo called with x=%r, y=%r' % (x, y)
>>  ...
>>  >>> foo2 = foo.__get__(2)
>>  >>> foo2('xxx')
>>  foo called with x=2, y='xxx'
>
>This is a side effect of part of the mechanism used to
>implement bound methods. It's probably best to regard it
>as an implementation detail subject to change.
Ok.

>
>There are clearer, more reliable and more general ways
>to get currying if you want it, e.g.
>
>   def foo(x):
>     def foo2(y):
>       ...do something with x and y
>     return foo2
>
You mention currying, but not the more general example
that was in my post. I'm not sure how to interpret that ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list