10-31-2024 11:37 AM
I don't fully understand the purpose of the output terminal on the python node input parameter which I have pointed out in the image above. You'll note that the online documentation doesn't show these outputs as being wired, so why do they exist?
When discussing the input parameter, the online documentation says "You can resize the Python Node to add more terminals. You pass a value to the Python function by wiring to the left terminal of a terminal pair. You read the value of a parameter after the function call by wiring from the right terminal of a terminal pair."
I'm interested in the part about reading the value of a parameter after the function call. My questions for the experts are:
1. Can the parameter change during the function call or will it always be identical to the value passed into the input parameter?
2. If it is always identical, why bother with the output terminal? Perhaps it could be used to control data flow, but the session out and/or error output is better for that purpose.
thanks
01-04-2025 03:29 PM
@dvonch wrote:1. Can the parameter change during the function call or will it always be identical to the value passed into the input parameter?
I am no Python expert, so sorry in advance for not using the correct technical terms, but I think in Python, all values are essentially objects, which are passed by reference to functions. Then, depending whether the data type of the object is mutable or not, it can or cannot be changed after creation. The mutability and the passing by reference effectively allows you to modify a parameter from within a function and get a modified value as an output.
Numerics, Strings, Tuples (Clusters in LV) and Booleans are immutable, meaning they cannot be changed once created.
Lists (Arrays in LV) are mutable, meaning they can be modified after creation.
Example:
Here you can see:
- the string given as parameter "text" has not been modified (re-affecting it in the function only creates a new string, but doesn't modify the original one)
- the array given as parameter "list1" has not been modified (idem, re-affecting it does not modify the original)
- the array given as parameter "list2" has effectively been modified through the "append" method of the List object in Python.
Regards,
Raphaël.