我有几个字符串处理函数,例如:
def func1(s):
return re.sub(r'\s', "", s)
def func2(s):
return f"[{s}]"
...
Run Code Online (Sandbox Code Playgroud)
我想将它们组合成一个管道函数: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]"
Run Code Online (Sandbox Code Playgroud)
目标是用作my_pipeline参数,否则我需要一一调用这些函数。
谢谢。