在python中对两个函数进行拼接,具体方法如下:
1.首先,定义一个装饰工厂;
def decorator_factory(inner_func):
def decorator(outer_func):
def wrapper(*args, **kwargs):
return outer_func(*inner_func(*args, **kwargs))
return wrapper
return decorator
2.装饰工厂定义好后,通过使用装饰工厂进口实现函数拼接;
def f(a, b):
return a, b+2, b+3
@decorator_factory(f)
def g(a, b, c):
return a+b+c
print g(1, 2)
# output: 10
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python怎么将两个列表拼接