Yesterday I got caught in the old copy-versus-reference trap and it took me a long while to locate the problem. I wrote:
if self.cash:
self.__dict__['cash2'] = self.__dict__['cash1']
self.__dict__['cash3'] = self.__dict__['cash1']
When I wanted:
if self.cash:
self.__dict__['cash2'] = list(self.__dict__['cash1'])
self.__dict__['cash3'] = list(self.__dict__['cash1'])
I have two questions related to the disparate behaviors of the assignment operator (=).
Why does Python behave this way?
When would one want a reference instead of a copy?
Maybe if I grok this I can avoid shooting myself in the foot again.