ALTERYX INSPIRE | Join us this May for for a multi-day virtual analytics + data science experience like no other! Register Now

Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

What is the best practice for passing the Question type Constants into Python Tool?

dylan_gao
7 - Meteor

Dear all, I'm wondering what is the best practice for passing the Question type Constants into Python tool?  

 

1) If I refer the Question type Contants by wrap it in %, unlike the R tool, the Python tool show errors. Even though it works, the error msg is annoying, and according to the Python Tool documentation, wrapping it in % is not the best practice and can have unexpectted outcomes.

2) Workflow Constants, can be directly referred(see Pic)

3) I found a way to fix the problem, but i think it's not the elegant/right way.

 

 

Thanks

 

Snipaste_2021-02-22_16-00-56.jpgget_workflow_constants.jpg

TrevorS
Moderator
Moderator

Hello @dylan_gao 

I found this post in the Community and I hope this will help you out!
https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Use-Question-lt-name-gt-in-Python/td-p...

Thanks!
TrevorS

Community Moderator
dylan_gao
7 - Meteor

Hi TravorS, thanks for sharing the post. I have the exactly the same questions.

I knew there are ways to tackle it, but i'm wondering is there any best practice on this? 

 

Thanks.

MatthewP
Alteryx
Alteryx

Hello @dylan_gao ,

 

When it comes to best practices with python we tend to suggest the same best practices of python itself. So it is mostly about knowing what the data structure/type are that you are working with.

 
For example the dataframe inputs it is best to look up by keys and find the values or you can do a iloc if you need to loop through the data to do something with.
 
However on the other hand "Alteryx.getWorkflowConstantNames()" will return a list so if they want to work with a value in that list.
 
Now as for the "%" that just functions differently than R. 
dylan_gao
7 - Meteor

Perfect, got it. Many thanks, Matthew. I'll accept your answer the solution now.

 

I'm also like to thank  @TrevorS  for helping me on the problem. 

 

Cheers, 

Dylan

Labels