Hello everyone, I am new and just started to use ...
# prefect-community
a
Hello everyone, I am new and just started to use prefect. I already have my first question: Is it possible to give a variable (created in task number 1) to another task (task number 2)? Up until know I did not find a solution for passing variables from task to task
a
Hi, welcome. Yes, definitly. You can use the Funtional API described here https://docs.prefect.io/core/getting_started/first-steps.html#tasks Heres the basic example they give:
Copy code
with Flow("My first flow!") as flow:
    first_result = add(1, y=2)
    second_result = add(x=first_result, y=100)
upvote 4
🚀 2
💯 1
n
Hi @Agostino Calamia, totally possible! A good example of passing results between tasks is here: https://docs.prefect.io/core/concepts/tasks.html#collections!
👍 1
a
Great! Thanks you two! So I user the task decorator at the moment und then define a function. In the first one I define a variable which I can then access in the second function, right?
I mean outside a flow and more in previous steps in a python script
n
Good question - since each task is a discreet unit of logic, variables can only be accessed if they're returned from the task in question and then passed to another task
a
Ah okay thanks! Unfortunately I just found this in the docs: https://docs.prefect.io/core/concepts/logging.html#logging-from-tasks
Thank you for the help
😄 1