[Edu-sig] what you can do in a shell
kirby urner
kirby.urner at gmail.com
Thu Sep 28 03:24:17 CEST 2006
Question:
The PEP on the 2.5 release schedule (2.5 Final already reached),
claims PEP 309 was somewhere implemented -- some way to curry
functions with partial. Anyone know where it is. Our own edu-sig's
Scott...
http://www.python.org/dev/peps/pep-0356/
Oh wait, I just found it:
>>> import functools
>>> dir(functools)
['WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', '__builtins__', '__doc__',
'__file__', '__name__', 'partial', 'update_wrapper', 'wraps']
So using that same g from before:
>>> def g(x,m=1,b=0): return m*x + b # slope-intercept linear
>>> G = functools.partial(g,m=0.25,b=2)
>>> G
<functools.partial object at 0x00D0ACF0>
>>> [(x,G(x)) for x in range(8)]
[(0, 2.0), (1, 2.25), (2, 2.5), (3, 2.75), (4, 3.0), (5, 3.25), (6,
3.5), (7, 3.75)]
Kwel.
Kirby
More information about the Edu-sig
mailing list