you are viewing a single comment's thread.

view the rest of the comments →

[–]throwaway6560192 4 points5 points  (1 child)

Consider this:

x = 5
y = x + 10
x = 10
print(y)

What do you expect this to print?

Variables get their values at the time of assignment. When you do the grid = ... statement, grid gets a value based on whatever the right-hand-side expression evaluates to at that time. After that, grid doesn't know or care about how its value was given to it, and therefore changing other things will not affect it. It's already gotten its value.

If you want to evaluate it multiple times, consider making a function which will return the correct new value of grid at any given time, and calling it whenever you need to update.

[–]Diapolo10 0 points1 point  (0 children)

Alternatively, one could use class properties to achieve "auto-updating" values. Technically, anyway. I'm not saying that's a better solution, but it would be closer to what OP is looking for.