How to pass string between operators?
Haoyang
New Altair Community Member
I am working on an extension where I will define a model in a string with some operator and then pass the model to a Python operator to parse the model. I noticed that I can only deliver IOObject through the output ports, how can I pass a string between ports? How can I pass a string from self-defined operators to a Python script operator as input?
Tagged:
0
Best Answers
-
Hi,
what you could also try:
- Generate the complete python code and pass it as a FileObject (for the scr port) or call the Execute Python operator from your code
- Use Macros
Greetings,
Jonas0
Answers
-
Hi @CKönig
Could you give me some examples? I still have no idea.If I want to pass a string from input port to output port, what should I do?And if I want to process the string in a python script operator, how should I format the string in the former output port?Thank you!0 -
Here is an example process how to take the strings from a dataset into python, work with them and return them to RM again.<?xml version="1.0" encoding="UTF-8"?><process version="10.2.000"><context><input/><output/><macros/></context><operator activated="true" class="process" compatibility="10.2.000" expanded="true" name="Process"><parameter key="logverbosity" value="init"/><parameter key="random_seed" value="2001"/><parameter key="send_mail" value="never"/><parameter key="notification_email" value=""/><parameter key="process_duration_for_mail" value="30"/><parameter key="encoding" value="SYSTEM"/><process expanded="true"><operator activated="true" class="retrieve" compatibility="10.2.000" expanded="true" height="68" name="Retrieve Golf" width="90" x="45" y="34"><parameter key="repository_entry" value="//Samples/data/Golf"/></operator><operator activated="true" class="blending:select_attributes" compatibility="10.2.000" expanded="true" height="82" name="Select Attributes" width="90" x="179" y="34"><parameter key="type" value="include attributes"/><parameter key="attribute_filter_type" value="one attribute"/><parameter key="select_attribute" value="Outlook"/><parameter key="select_subset" value=""/><parameter key="also_apply_to_special_attributes_(id,_label..)" value="true"/><description align="center" color="transparent" colored="false" width="126">Keep the nominal attribute &quot;Outlook&quot;, where every entry can be considered a &quot;String&quot;</description></operator><operator activated="true" class="python_scripting:execute_python" compatibility="10.0.001" expanded="true" height="103" name="Execute Python" width="90" x="313" y="34"><parameter key="script" value="import pandas # rm_main is a mandatory function, # the number of arguments has to be the number of input ports (can be none), # or the number of input ports plus one if "use macros" parameter is set # if you want to use macros, use this instead and check "use macros" parameter: #def rm_main(data,macros): def rm_main(data): # add a new column with reversed strings of column "Outlook" data["Outlook_reversed"]=data["Outlook"].str.split('').apply(lambda x: ''.join(x[::-1])) return data "/><parameter key="notebook_cell_tag_filter" value=""/><parameter key="use_default_python" value="true"/><parameter key="package_manager" value="conda (anaconda)"/><parameter key="use_macros" value="false"/></operator><connect from_op="Retrieve Golf" from_port="output" to_op="Select Attributes" to_port="example set input"/><connect from_op="Select Attributes" from_port="example set output" to_op="Execute Python" to_port="input 1"/><connect from_op="Execute Python" from_port="output 1" to_port="result 1"/><portSpacing port="source_input 1" spacing="0"/><portSpacing port="sink_result 1" spacing="0"/><portSpacing port="sink_result 2" spacing="0"/></process></operator></process>0
-
@"CKönig"Thank you for the example.However I am working on an extension here, and I guess I can only pass a string like "This is a String" with an IOTable under an attribute "XX"?At this time I built a new IO type to pass the string between non-python operators, if python operator can only get data from a pandas data frame, maybe I should follow the IOTable way of doing this.0
-
Hi,
what you could also try:
- Generate the complete python code and pass it as a FileObject (for the scr port) or call the Execute Python operator from your code
- Use Macros
Greetings,
Jonas0