Correct me if I am wrong. I wonder why this is not...
# prefect-community
j
Correct me if I am wrong. I wonder why this is not supported and maybe it's in the future development?
j
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
j
ahh, that makes sense.
j
does that make sense?
👌
j
thanks for the suggestion! you are right
j
I’m glad you’re having a good experience otherwise and definitely keep asking with any questions you have!
j
😀
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
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
Thank you, Chris. I get what you meant🙂