load/store - create new object?
Posted: Fri Mar 02, 2018 9:48 pm
In .attr function, should I create a copy of the object when storing/loading or use the one that was passed in?
Online community discussing all things related to MicroPython
Is there a way, in Python language, to distinguish between those two types of loads?dhylands wrote: ↑Fri Mar 02, 2018 11:35 pmYou could do either. It really depends on your application and whether the object passed in is mutable or not. If it is mutable, do you want to see changes that are made?
If you were to do something like
x = [ 1, 2, 3]
x = 4
Do you want your stored value to be [1,2,3] or [1,4,3]?
The answer to that question is the answer to your question.