Using Method in Flow
In this section, you'll learn how to use methods withing the flow. We'll expand the "Hello World" example by adding a method to the flow.
Syntax
Breakdown of Syntax
flow HelloWorld_UsingMethod -> None:
- Declares a new flow named
HelloWorld_UsingMethod
, which represents a Python class. -> None
specifies that the flow does not return a value.
- Declares a new flow named
method greet using constant
- Defines a mixin inclusion in the flow that tells the fy tool that the flow class has to inherit the method mixin class.
- Code Generation:
- Everything between
# fy:start
and# fy:end
is automatically generated by the fy tool. - The generated code includes the class definition
HelloWorld_Flow
, which incorporates theGreet_UsingConstant_MethodMixin
mixin and theFlowBase
base class. - fy tool adds necessary imports, such as
Greet_UsingConstant_MethodMixin
, which contains thegreet
method, andFlowBase
for flow base class functionality. It adds imports only when they do not exist. - The
__call__
method calls the_greet
method.
- Everything between
- User Input:
- The only code the user needs to write is the flow declaration within the
"""fy
block. After generation, the user can add custom logic, such asself._greet()
.
- The only code the user needs to write is the flow declaration within the