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.

Cheers,
Ana

2 Likes

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.
Martin

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:

Cheers
Ana

4 Likes

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.
Cheers,
Martin

1 Like