functools.partial
returns a callable wrapping a function with some or all of the arguments frozen.
import sys
import functools
print_hello = functools.partial(sys.stdout.write, "Hello world
")
print_hello()
Hello world
The above usage is equivalent to the following lambda
.
print_hello = lambda *a, **kw: sys.stdout.write("Hello world
", *a, **kw)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…