Anish Chhaparwal
01/07/2021, 8:00 PMfrom prefect import Flow, Task, Parameter
class PrintTheStatements(Task):
def task_1():
print(f"first name is {self.firstname} and last name is {self.lastname}")
def run(self, firstname, lastname):
self.firstname = firstname
self.lastname = lastname
task_1()
if __name__ == "__main__":
with Flow("ClassTask") as flow:
firstname = Parameter("firstname", default="anish")
lastname = Parameter("lastname", default="chhaparwal")
apt = PrintTheStatements()
result = apt(firstname=firstname, lastname=lastname)
flow.run()
Amanda Wee
01/07/2021, 8:05 PMtask_1()
rather than self.task_1()
Anish Chhaparwal
01/07/2021, 8:09 PMAmanda Wee
01/07/2021, 8:13 PMresult = PrintTheStatements(firstname, lastname)
in such a case the run
method will replace the task_1
method.run
when run
can replace task_1
. Having a constructor instead means that you could customise the task before running it.Anish Chhaparwal
01/07/2021, 8:35 PM