<@ULVA73B9P> how can i print the task name in the ...
# ask-marvin
h
@Marvin how can i print the task name in the task in prefect 3.0
m
In Prefect 3.0, if you want to print the task name within a task, you can use the
prefect.runtime
module to access task run information. Here's a sample code snippet that demonstrates how to access the task name:
Copy code
python
from prefect import task, flow
from prefect.runtime import task_run

@task
def my_task():
    current_task_name = task_run.task_name
    print(f"The current task name is: {current_task_name}")

@flow
def my_flow():
    my_task()

if __name__ == "__main__":
    my_flow()
In this example, the
task_run.task_name
retrieves the name of the task at runtime, which you can then print. For more information, you can refer to the Prefect 3.0 documentation on writing tasks. This document provides additional examples and explanations on how to utilize task run metadata effectively.