Hi, trying to print out the `date` and `today` con...
# ask-community
w
Hi, trying to print out the
date
and
today
context in a task, but getting None.
Copy code
date = prefect.context.get("date")
today = prefect.context.get("today")
def get_data():

    print(f"{date}")
    print(today)
a
you would need to print it from a task
w
Hi Anna, I added the
@task
and reran, the output in the terminal is still None.
a
try this:
Copy code
from prefect import Flow, task
import prefect


@task(log_stdout=True)
def hello_world():
    date = prefect.context.get("date")
    today = prefect.context.get("today")
    print(f"Today {today} is {date}")


with Flow("flow_giving_you_some_context") as flow:
    hw = hello_world()

if __name__ == '__main__':
    flow.run()
should output sth like:
Copy code
[2022-03-29 23:00:26+0200] INFO - prefect.FlowRunner | Beginning Flow run for 'flow_giving_you_some_context'
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Task 'hello_world': Starting task run...
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Today 2022-03-29 is 2022-03-29T21:00:26.879376+00:00
[2022-03-29 23:00:26+0200] INFO - prefect.TaskRunner | Task 'hello_world': Finished task run for task with final state: 'Success'
[2022-03-29 23:00:26+0200] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
w
ahh, there it is. I understand now.
👍 1
thanks!