Message74682
When I partially apply a function using functools.partial(), the
resultant function doesn't have the same name as the original function
(it has no __name__) and its docstring is that of functools.partial()
rather than that of the function that was partially applied.
Transcript:
Python 2.6 (r26:66714, Oct 13 2008, 10:32:02)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>> import functools
>>> def sum(a,b,c):
... return a+b+c
...
>>> functools.partial(sum,1)
<functools.partial object at 0xf7efeb6c>
>>> p = functools.partial(sum, 1)
>>> p.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'functools.partial' object has no attribute '__name__'
>>> p(2,3)
6
>>> sum.__name__
'sum'
>>> sum.__doc__
>>> p.__doc__
'partial(func, *args, **keywords) - new function with partial
application\n\tof the given arguments and keywords.\n' |
|
Date |
User |
Action |
Args |
2008-10-13 11:45:15 | stribb | set | recipients:
+ stribb |
2008-10-13 11:45:15 | stribb | set | messageid: <1223898315.71.0.950281538816.issue4113@psf.upfronthosting.co.za> |
2008-10-13 11:45:14 | stribb | link | issue4113 messages |
2008-10-13 11:45:13 | stribb | create | |
|