【发布时间】:2022-06-27 21:26:43
【问题描述】:
我有几个字符串处理函数,例如:
def func1(s):
return re.sub(r'\s', "", s)
def func2(s):
return f"[{s}]"
...
我想将它们组合成一个管道函数:my_pipeline(),以便我可以将其用作参数,例如:
class Record:
def __init__(self, s):
self.name = s
def apply_func(self, func):
return func(self.name)
rec = Record(" hell o")
output = rec.apply_func(my_pipeline)
# output = "[hello]"
目标是使用my_pipeline作为参数,否则需要一一调用这些函数。
谢谢。
【问题讨论】:
标签: python function pipeline chain