"Collapsing" a list into a list of changes

Francis Girard francis.girard at free.fr
Mon Feb 7 17:04:18 EST 2005


Le lundi 7 Février 2005 22:53, Steven Bethard a écrit :
> Francis Girard wrote:
> > I see. I personnaly use them frequently to bind an argument of a function
> > with some fixed value. Modifying one of the example in
> > http://mail.python.org/pipermail/python-list/2004-December/257990.html
> > I frequently have something like :
> >
> > SimpleXMLRPCServer.py:  server.register_1arg-place_function(lambda x:
> > x+2, 'add2')
>
> PEP 309 has already been accepted, so I assume it will appear in Python
> 2.5:
>
>      http://www.python.org/peps/pep-0309.html
>
> Your code could be written as:
>
>      server.register_1arg-place_function(partial(operator.add, 2))
>
> If your task is actually what you describe above -- "to bind an argument
> of a function with some fixed value"[1] -- then in general, you should
> be able to write this as[2]:
>
>      function_with_fixed_value = partial(function, fixed_value)
>

Great ! Great ! Great !
Really, Python is going in the right direction all of the time !
Very good news.

Regards

Francis Girard

>
> Steve
>
> [1] As opposed to binding a name to be used in an _expression_ as you do
> in your example.
>
> [2] The partial function can also be used to fix multiple argument
> values and keyword argument values, if that's necessary for your purposes.




More information about the Python-list mailing list