https://prefect.io logo
Title
j

Jie Lou

07/19/2019, 8:09 PM
Correct me if I am wrong. I wonder why this is not supported and maybe it's in the future development?
j

Jeremiah

07/19/2019, 8:11 PM
Hi @Jie Lou — you’re correct, the multiple assignment you’re attempting is not supported. That’s because when you’re building your flow, Prefect has no way of knowing what’s going to be returned from the task — it’s building the computational graph, but not executing it, so we don’t know (yet) that there are two items to assign.
However, I would suggest a slightly different variant of your solution. As proposed, you are going to run your task two times and then grab the first and second result of those two runs, respectively.
Instead, try:
task_result = task_function(...)
result1 = task_result[0]
result2 = task_result[1]
This represents a single execution of the task, and then two indexes (which are secretly tasks themselves) of that single result
j

Jie Lou

07/19/2019, 8:12 PM
ahh, that makes sense.
j

Jeremiah

07/19/2019, 8:12 PM
does that make sense?
:yes:
j

Jie Lou

07/19/2019, 8:12 PM
thanks for the suggestion! you are right
j

Jeremiah

07/19/2019, 8:12 PM
I’m glad you’re having a good experience otherwise and definitely keep asking with any questions you have!
j

Jie Lou

07/19/2019, 8:13 PM
😀
A new question: what if a function returns (let's say) 20 objects and then i need to write 20 line codes to declare them...is there any efficient way to solve? thx
c

Chris White

07/19/2019, 10:17 PM
Hi @Jie Lou sorry just seeing this question --> could you explain your use case for this a little more? If you need to process each item individually, maybe take a look at Task Mapping: https://docs.prefect.io/guide/core_concepts/mapping.html
j

Jie Lou

07/22/2019, 1:34 PM
Thank you, Chris. I get what you meant🙂