Icon

kn_​example_​python_​component_​py_​module

use a component to create individual python code dynamically in a sub-folder

use a component to create individual python code dynamically in a sub-folder
... well admittedly not the most elegant solution
https://forum.knime.com/t/portable-python-components/44199/7?u=mlauber71

import knime_io as knio# This example script creates an output table containing randomly drawn integers using numpyand pandas.import numpy as npimport pandas as pdimport sysfrom pandas import DataFramev_path_to_script = knio.flow_variables['path_modules']# Add workflow directory to sys.path. Alternatively, use importlib.util.sys.path.append(v_path_to_script)# Loads module my_module.py which is located in the workflow directory.import my_module# Call some function.my_script_output_1 = my_module.my_function_1()# Output to KNIMEoutput_table = DataFrame({"Output": [my_script_output_1]})knio.output_tables[0] = knio.write_table(output_table) in the sub-folder script/ there is a folder/modules/ # the folder gets added to the sys.path to be found __init__.py # containing initialization and will # be loaded by default once my_module gets imported # from .my_module import my_function_1 # the .py file my_module is adressed with a 'relative' path my_module.py # containes the function "def my_function_1():" .... use a component to create individual python code dynamically in a sub-folder... well admittedly not the most elegant solutionhttps://forum.knime.com/t/portable-python-components/44199/7?u=mlauber71 Propagate Python environmentfor KNIME on Windows withMinicondaconfigure how to handle the environmentdefault = just check the namesuse the functionfrom the modulefrom the componentPropagate Python environmentfor KNIME on MacOSX withMinicondaconfigure how to handle the environmentdefault = just check the names conda_environment_kaggle_windows Python Script(Labs) conda_environment_kaggle_macosx py_internal_module Merge Variables import knime_io as knio# This example script creates an output table containing randomly drawn integers using numpyand pandas.import numpy as npimport pandas as pdimport sysfrom pandas import DataFramev_path_to_script = knio.flow_variables['path_modules']# Add workflow directory to sys.path. Alternatively, use importlib.util.sys.path.append(v_path_to_script)# Loads module my_module.py which is located in the workflow directory.import my_module# Call some function.my_script_output_1 = my_module.my_function_1()# Output to KNIMEoutput_table = DataFrame({"Output": [my_script_output_1]})knio.output_tables[0] = knio.write_table(output_table) in the sub-folder script/ there is a folder/modules/ # the folder gets added to the sys.path to be found __init__.py # containing initialization and will # be loaded by default once my_module gets imported # from .my_module import my_function_1 # the .py file my_module is adressed with a 'relative' path my_module.py # containes the function "def my_function_1():" .... use a component to create individual python code dynamically in a sub-folder... well admittedly not the most elegant solutionhttps://forum.knime.com/t/portable-python-components/44199/7?u=mlauber71 Propagate Python environmentfor KNIME on Windows withMinicondaconfigure how to handle the environmentdefault = just check the namesuse the functionfrom the modulefrom the componentPropagate Python environmentfor KNIME on MacOSX withMinicondaconfigure how to handle the environmentdefault = just check the names conda_environment_kaggle_windows Python Script(Labs) conda_environment_kaggle_macosx py_internal_module Merge Variables

Nodes

Extensions

Links