キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

Python node read value of input parameter

解決済み
解決策を見る

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 件の賞賛
メッセージ1/4
1,279件の閲覧回数
解決策
トピック作成者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.

メッセージ2/4
1,153件の閲覧回数

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

0 件の賞賛
メッセージ3/4
1,111件の閲覧回数

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 件の賞賛
メッセージ4/4
1,102件の閲覧回数