I have a custom python parameter that holds a list. How can I script a modification of this list?
node.par.Pythonpar.eval().append(123) does not work
You tried
node.par.Pythonpar = node.par.Pythonpar.eval().append(123)
depending on what yo have in the par already
?
Yes, i did. It results in None as the par value
I had [1,2] in the par already
see: pythonpar.toe (3.7 KB)
n.par.Py = n.par.Py.eval() + [123] works.
So why not what you had… not sure. .append() changes an existing list by adding a member. the .eval() creates a temporary list object, then .append appends to that temporary object. maybe it’s lost when the assignment is made.
thanks greg, that works
The reason the other didn’t work is because the list that you get out of the par (node.par.Pythonpar.eval()) is not the list object that is stored in the par, but a copy of it. So appending to it changes the copy but not the parameter. Greg’s method works because it reassigns the newly added-to copy back to the parameter.