Icon

kn_​example_​python_​flow_​variable_​if_​switch

Three ways to handle combination of Flow variables from Python and If switches

Three ways to handle combination of Flow variables from Python and If switches

In one Python environment a Flow Variable for the usage in KNIME will be filled and the results will be used for two If switches.

if($${Ivar_py_value_switch}$$ >0) {return "bottom";}
else {return "top";}


decide ifTOP or BOTTOM import knime.scripting.io as knioimport sysimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)input_table = knio.input_tables[0].to_pandas()# this setting will be used as a flow variable in KNIME# knio.flow_variables['var_py_value_switch'] = 0knio.flow_variables['var_py_value_switch'] = 1var_py_version = sys.versionvar_py_version_pandas = pd.__version__knio.flow_variables['var_py_version'] = sys.versionknio.flow_variables['var_py_version_pandas'] = pd.__version__data = {'sys_version': [var_py_version], 'pandas_version': [var_py_version_pandas] }knio.output_tables[0] = knio.Table.from_pandas(input_table.copy())# pass column names in the columns parameter knio.output_tables[1] = knio.Table.from_pandas(pd.DataFrame(data)) Three ways to handle combination of Flow variables from Python and If switcheshttps://forum.knime.com/t/to-control-workflow-stream-using-if-switch-using-flow-variable-from-a-python-snippet/27913/2?u=mlauber71In one Python environment a Flow Variable for the usage in KNIME will be filled and the results will be used for two If switches. Vernalis KNIME Nodeshttps://hub.knime.com/vernalis/extensions/com.vernalis.knime.feature/latest dummydatav_result_switchSTARTresult Pythonv_result_switch"top"or "bottom"derived from Pythonvar_py_value_switchtop_result.xlsxtop_result.xlsxv_result_case_portwhich port should be activederived from Pythonvar_py_value_switchresultv_result_switchSTARTsome Python scripttop Pythonbottom PythonENDtop Pythonbottom Pythontop Pythonv_result_case_portbottom Python Data Generator IF Switch End IF Java EditVariable (simple) Excel Writer Excel Writer Java EditVariable (simple) CASE Switch End Configurable IF/CASE Switch(Flow Variable Value) Python Script Python Script Python Script ConfigurableEnd IF/CASE Python Script Python Script Python Script CASE Switch Start Python Script decide ifTOP or BOTTOM import knime.scripting.io as knioimport sysimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)input_table = knio.input_tables[0].to_pandas()# this setting will be used as a flow variable in KNIME# knio.flow_variables['var_py_value_switch'] = 0knio.flow_variables['var_py_value_switch'] = 1var_py_version = sys.versionvar_py_version_pandas = pd.__version__knio.flow_variables['var_py_version'] = sys.versionknio.flow_variables['var_py_version_pandas'] = pd.__version__data = {'sys_version': [var_py_version], 'pandas_version': [var_py_version_pandas] }knio.output_tables[0] = knio.Table.from_pandas(input_table.copy())# pass column names in the columns parameter knio.output_tables[1] = knio.Table.from_pandas(pd.DataFrame(data)) Three ways to handle combination of Flow variables from Python and If switcheshttps://forum.knime.com/t/to-control-workflow-stream-using-if-switch-using-flow-variable-from-a-python-snippet/27913/2?u=mlauber71In one Python environment a Flow Variable for the usage in KNIME will be filled and the results will be used for two If switches. Vernalis KNIME Nodeshttps://hub.knime.com/vernalis/extensions/com.vernalis.knime.feature/latest dummydatav_result_switchSTARTresult Pythonv_result_switch"top"or "bottom"derived from Pythonvar_py_value_switchtop_result.xlsxtop_result.xlsxv_result_case_portwhich port should be activederived from Pythonvar_py_value_switchresultv_result_switchSTARTsome Python scripttop Pythonbottom PythonENDtop Pythonbottom Pythontop Pythonv_result_case_portbottom PythonData Generator IF Switch End IF Java EditVariable (simple) Excel Writer Excel Writer Java EditVariable (simple) CASE Switch End Configurable IF/CASE Switch(Flow Variable Value) Python Script Python Script Python Script ConfigurableEnd IF/CASE Python Script Python Script Python Script CASE Switch Start Python Script

Nodes

Extensions

Links