https://prefect.io logo
l

Luis Gallegos

01/20/2021, 11:28 PM
Hi, Quick Question: How i can use the parameter input as a string outside a task. When i try it , i get a parameter object <Parameter: example>
Copy code
with Flow("example-flow") as flow:
	example_param = Parameter('example')

	print(example_param)
Thanks for your help!!
z

Zanie

01/20/2021, 11:29 PM
Hi! The short answer is that you can’t. The Parameter is intended to be resolved at flow runtime and anything that’s outside a task is executed at flow definition time.
If you absolutely want to print the value of that parameter at flow definition time, you can use
print(example_param.run())
l

Luis Gallegos

01/20/2021, 11:35 PM
I Understand. So i intend to do is change the run_flow_name with the parameter input like this:
Copy code
with Flow("example-flow") as flow:
	example_param = Parameter('example')
	current_time = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
	run_name = f"{example_param} - {current_time}"

	rename_flow = RenameFlowRun(flow_run_name=run_name)
I try it inside a task, but doesn't work. (Any suggest?) I will try with the
run
method. Thanks
z

Zanie

01/20/2021, 11:37 PM
You’ll need to generate the name in a task, here you’re both getting the current time and formatting a string at flow definition time rather than runtime.
l

Luis Gallegos

01/20/2021, 11:38 PM
Sounds like a good idea! Thanks @Zanie 👏
z

Zanie

01/20/2021, 11:38 PM
So
Copy code
@task
def generate_new_name(param):
    current_time = datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
  	return f"{param} - {current_time}"

with Flow(...):
   ...
   rename_flow = RenameFlowRun()(flow_run_name=generate_new_name(example_param))
1
2 Views