functools.partial doesn't work without using named parameter
Paddy
paddy3118 at googlemail.com
Fri Mar 25 02:30:29 EDT 2011
Hi, I just found the following oddity where for function fsf1 I am forced to use a named parameter for correct evaluation and was wondering why it doesn't work, yet the example from the docs of wrapping int to create basetwo doesn't need this?
The example:
>>> from functools import partial
>>> basetwo = partial(int, base=2)
>>> basetwo('10010')
18
>>>
>>> def fs(f, s): return [f(value) for value in s]
>>> def f1(value): return value * 2
>>> s = [0, 1, 2, 3]
>>> fs(f1, s)
[0, 2, 4, 6]
>>>
>>> fsf1 = partial(fs, f=f1)
>>> fsf1(s)
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
fsf1(s)
TypeError: fs() got multiple values for keyword argument 'f'
>>> # BUT
>>> fsf1(s=s)
[0, 2, 4, 6]
>>>
Would someone help?
- Thanks in advance, Paddy.
More information about the Python-list
mailing list