status of foo.__get__ ?

Greg Ewing (using news.cis.dfn.de) g2h5dqi002 at sneakemail.com
Mon May 26 22:41:22 EDT 2003


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.

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

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list