Python 通用函数调度
Python generic functions dispatching
是否有任何方法可以分派参数可能是的函数:
- 单个 lambda 函数(即
func(lambda x: x)
)
- kwargs(即
func(a='some sting', b='some other string')
)
如我所见,functools
中的 singledispatch
装饰器仅支持对第一个参数进行分派,这在我的例子中是行不通的。我错过了什么吗?
你没有遗漏任何东西。一次派遣解决不了你的问题
https://pypi.python.org/pypi/multipledispatch
可以帮助您处理位置参数但不能处理关键字:(
是否有任何方法可以分派参数可能是的函数:
- 单个 lambda 函数(即
func(lambda x: x)
) - kwargs(即
func(a='some sting', b='some other string')
)
如我所见,functools
中的 singledispatch
装饰器仅支持对第一个参数进行分派,这在我的例子中是行不通的。我错过了什么吗?
你没有遗漏任何东西。一次派遣解决不了你的问题
https://pypi.python.org/pypi/multipledispatch
可以帮助您处理位置参数但不能处理关键字:(