LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python node read value of input parameter

Solved!
Go to solution

dvonch_1-1730392561996.png

 

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

0 Kudos
Message 1 of 4
(235 Views)
Solution
Accepted by dvonch

@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:

 

raphschru_2-1736025946989.png

 

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.

Message 2 of 4
(109 Views)

Excellent explanation! Thank you! I hope the details you provide will be added to the official python node documentation.

0 Kudos
Message 3 of 4
(67 Views)

Oops, small typo in my previous answer.

In "TestFunction", "name" should be replaced by "text".

This is the problem with not having to declare variables with Python, a typo won't necessarily give you an error.

 

 


@dvonch wrote:

I hope the details you provide will be added to the official python node documentation.


I hope too.

0 Kudos
Message 4 of 4
(58 Views)