Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
>>> dir(functools)
['WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'cmp_to_key', 'partial', 'reduce', 'total_ordering', 'update_wrapper', 'wraps']
一、partial函数
他可以重新绑定函数的可选参数,生成一个callable的partial对象
对于已知的函数参数若可以提前获知,可以减少更多的参数调用。
In [16]: from functools import partial
In [17]: int2 = partial(int, base=2)
In [18]: int2('10')
Out[18]: 2