Python 如何为每个和if组合_
我开始学习liteflow,想知道是否有可能以某种方式将每个的Python 如何为每个和if组合_,python,python-3.x,liteflow,Python,Python 3.x,Liteflow,我开始学习liteflow,想知道是否有可能以某种方式将每个的和如果组合起来。我尝试了以下方法: from liteflow.core import * class Hello(StepBody): def run(self, context: StepExecutionContext) -> ExecutionResult: print("Hello") return ExecutionResult.next() class DoStuff
和如果
组合起来。我尝试了以下方法:
from liteflow.core import *
class Hello(StepBody):
def run(self, context: StepExecutionContext) -> ExecutionResult:
print("Hello")
return ExecutionResult.next()
class DoStuff(StepBody):
def run(self, context: StepExecutionContext) -> ExecutionResult:
print(f"doing stuff...{context.execution_pointer.context_item}")
return ExecutionResult.next()
class Goodbye(StepBody):
def run(self, context: StepExecutionContext) -> ExecutionResult:
print("Goodbye")
return ExecutionResult.next()
class MyWorkflow(Workflow):
def id(self):
return "MyWorkflow"
def version(self):
return 1
def build(self, builder: WorkflowBuilder):
builder\
.start_with(Hello)\
.for_each(lambda data, context: ["abc", "def", "xyz"])\
.if_(lambda d, c: not d.startswith("x"))\
.do(lambda x: x.start_with(DoStuff))\
.then(Goodbye)
host = configure_workflow_host()
host.register_workflow(MyWorkflow())
host.start()
wid = host.start_workflow("MyWorkflow", 1, None)
input()
host.stop()
这不起作用('NoneType'对象没有属性'startswith'
),如果我用0<1
DoStuff
之类的内容替换条件,则在没有if
的情况下,会执行一次而不是三次,甚至打印“错误”输出
我知道,在这个简单的例子中,我可以通过在中为每个使用一个LC来消除if(如果不是x.startswith(“x”)
),但是想象一个更复杂的工作流
那么,如何将for_each
和if
组合在一起,以便从if_each
中的for_each
访问循环变量,并将正确的上下文传递给do
?或者这是不可能的,我必须检查我的步骤的run
方法中的条件吗?您的问题首先被标记为liteflow
——您介意更新标记wiki吗(目前没有)?我不想只是从网站的“关于”部分复制/粘贴,而不真正了解它是关于什么的。@gst我不知道许可证是否允许我从网站复制粘贴,这就是为什么我还没有更新标签的原因。