Hi, I'm using mapped tasks to run a flow locally u...
# prefect-community
s
Hi, I'm using mapped tasks to run a flow locally using output = flow.run(). My mapped task calls have outputs (which should be an array based on what I'm passing in). Can i please get some assistance with accessing the array outputs from each mapped task call after I've run flow.run() when my result handler looks something like this attached screenshot? The data I need is circled at the bottom but I can't work out the syntax needed to get through the <Task: Save Sim Data> section. Thanks
👀 1
n
Hi @Sanjay Patel! I think you can use something like this:
Copy code
output.result[<task_ref>].result
where
<task_ref>
is the reference to the task you defined in your flow. In a simple flow:
Copy code
import prefect
from prefect import Flow, task

@task
def my_task()
  return [1, 2, 3]

with Flow("my-flow") as flow:
  my_task_result = my_task()

output = flow.run()

# this is the result of my_task
output.result[my_task_result].result
Let me know if I understood your question correctly!
s
yep, question understood exactly thanks. I'm calling it from a different location so just trying to access that my_task_result again. I'm trying it now. Thanks
👍 1
@nicholas ok, so I have two problems. 1. I don't have access to
my_task_result
, all I have saved is the
flow
and I run it in a different location. Is it possible to access the
my_task_result
from the
flow
object without it having been run? 2. Which may become clearer after #1 but I'm also using my_task.mapped() so I have an array
n
Gotcha @Sanjay Patel - you could try something like this:
Copy code
for ref in flow.get_tasks():
  print(output.result[ref].result)
and then further filter out the results you don't want
s
got it, that worked for now. thank you so much!
n
Great! 😄