Correct me if I am wrong. I wonder why this is not...
# prefect-community
Correct me if I am wrong. I wonder why this is not supported and maybe it's in the future development?
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:
Copy code
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
ahh, that makes sense.
does that make sense?
thanks for the suggestion! you are right
I’m glad you’re having a good experience otherwise and definitely keep asking with any questions you have!
A new question: what if a function returns (let's say) 20 objects and then i need to write 20 line codes to declare there any efficient way to solve? thx
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:
Thank you, Chris. I get what you meant🙂