简体   繁体   English

蟒蛇。 指定了一些参数的传递函数

[英]python. pass function with some parameters specified

I need pass function to another function with some parameters specified. 我需要将函数传递给指定了某些参数的另一个函数。 So half of parameters I need assign before passing function and other parameters would be given inside another function. 因此,在传递函数之前,我需要分配一半的参数,而其他参数将在另一个函数中给出。 How to do that? 怎么做?

This is exactly what functools.partial does. 这正是functools.partial所做的。 For example: 例如:

other_function(callback=functools.partial(the_other_function, param1='foo', param2='bar'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM