Python Forum

Full Version: Basic Pyhton for Rhino 6 question about variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I've been trying to create a sequence in which a new value is based on the older value.
then the values change making the new value the old one and create a new value and so on in a for loop.

the problem I'm facing is when assigning a variable to a variable. If a change happens to one variable the other one changes to match the first one

here is a simple and easy example:

pt1 = [1,1,1]
pt2 = pt1
pt1[2] = pt1[2] * 2
print(pt1)
print(pt2)

the result that shows up is as follows:

[1, 1, 2]
[1, 1, 2]

isn't it supposed to be?

[1, 1, 2]
[1, 1, 1]


why did pt2 change after modifying pt1?
is there a way to assign the values of the variable instead of its path?

Thanks to anyone
pt2 is a pointer to pt1, so they both share the same variable space. (an other name for the same variable)
id one changes since the other does as well since they are really one.
you can use the copy function if you want one to be a copy of and independent of the other.
https://docs.python.org/3/library/copy.h...odule-copy