Hi,
is there a way to use a dictionary returned from a task in the with Flow block? i read in some threads that it could be done using an intermediate task to unpack it,
any examples for such task?
k
Kevin Kho
09/15/2021, 9:47 PM
So I always told people to unpack it, but I was wrong. You actually can.
Copy code
@task()
def abc(x):
return {"a": 1, "b": 2}
with Flow("test") as flow:
a = abc(1)
test = a["a"]
flow.run()
Kevin Kho
09/15/2021, 9:48 PM
Copy code
@task()
def abc(x):
return {"a": 1, "b": 2}
@task()
def bcd(x):
return x
with Flow("test") as flow:
a = abc(1)
test = a["a"]
bcd(a["b"])
flow.run()
Kevin Kho
09/15/2021, 9:48 PM
The
[]
for a task calls the built-in Prefect
GetItem
task
n
Nadav
09/15/2021, 9:58 PM
@task
def a():
return {'list_key':['item1',item2']}
with Flow('test') as flow:
t = a()
li = t['list_key']
for item in li:
do_something(item1
)
Nadav
09/15/2021, 9:58 PM
will this work?
k
Kevin Kho
09/16/2021, 12:46 AM
This I don't think so. You should use
.map()
instead to loop. And then you need to unpack this yep.
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.