Can I create a flow variable in Python Snippet?

I have a python snippet, and in my use case, one output seems not enough. I need to output an additional string. Can I output this string as a flow varible of my Python snippet so that I can pass it to some other nodes later?

Thanks in advance!

No, this is not possible. Sorry

Unfortunately, I don't have any suggestion beside using two pyhton snippets doing the same with different output.

Thanks Niederle for your reply!

Let me ask you this way: if I create a flowvariable using an Input node, say, an Integer Input node. I can access this flow variable in my Python snippet. Can I set the flow variable to a new value? Or the flow variable has to be read only?

No, it is not possible to modify a flow variable within a python snippet (though you can access it in the snippet).

Hi Everyone,

I know I am reviving this old topic, but for those of you who came here after googling; this is currently possible with our Python integration (lots of things change in six years!). To generate a new flow variable from a python snippet, all you have to do is something like:

flow_variables[‘foo’] = (value you want)

And this would generate a new flow variable with the value you would like to have.



Hi Ana,
no, unfortunately that is not possible.
You would need to create a table containing that value, that you want as a python output to KNIME, and using the KNIME nodes to turn it into a variable.
The reason is Snippet output is just a single table and Plot output is just a single image. There is no other output.
Though you can access the flow variables using
my_variable = FLOWVAR(my_KNIME_flow_variable)
in the code, where FLOWVAR(my_KNIME_flow_variable) will be replaced with the content of the variable value.

Hi Stoeter

I am guessing this might be true if people are using python from the community extension, but in case they really need to do it, they can also use KNIME python integration to do it.
Again, multiple options available within KNIME, and I guess this was part of the confusion. Here is one example how to do it using the Python Integration nodes:



Hi Ana,
sorry I misread your post and thought you were asking, if that would be possible with the python community extensions. Thanks for making this clear. Sometimes people are mixing the two possibilities to work with python in KNIME.

1 Like

Hi Ana,
Can I possibly create a list as a flow variable via the python 1:1 node?
Best wishes,

Hi @rummelbe129 , When you say List, are you meaning a String[] array flow variable?

I don’t now about the python 1:1 node, but my experimentation with the general Python Script node indicates that whilst I can create a list it doesn’t resolve to a String[] array variable.

However, I do have a component using a Java snippet that could probably be used to turn a regular string flow variable into a String[] variable if the elements were separated by \n. So if you could generate a regular string from the python 1:1 it could probably be turned into an array. Would that assist?

Legal ver esse tópico de 2014. Estamos em 2021 e estou feliz da vida usando Python dentro do Knime. Rodando VBA a partir do Python dentro do Knime. Knime é feraaa!