[Edu-sig] what you can do in a shell

Dethe Elza delza at livingcode.org
Thu Sep 28 16:22:04 CEST 2006


On 27-Sep-06, at 6:24 PM, kirby urner wrote:

> 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/


One of the best ways to get up to speed quickly with the new features  
in a new version of Python is with Andrew Kuchling's "What's New"  
article in the standard documentation.  Here's the one for Python 2.5:

http://docs.python.org/whatsnew/whatsnew25.html

--Dethe

>
> 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
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig


"Say what you like about C++, but it's uninitialized variables will  
always
hold a special place in my heart. In a world where we define  
*everything*
concretely it is the last refuge of the undefined. It's the programmer's
Wild West, the untamed frontier." --Bjorn Stroustrap




More information about the Edu-sig mailing list