instance of object versus object value python -


i having difficulties understand instance of object in list. how save value of object list without saving instance? not possible isnt it? colde below works avoid use .value might have several parameters.. not sure if clear enough..

class bougiebuffer:     def __init__(self):         self.bougiebuffer=deque(maxlen = 10000)         self.maximum = maximum()      def update(self,bougie):         self.maximum.value = random.randint(-1,1)         bougie.maximum.value = self.maximum.value         self.bougiebuffer.append(bougie)         print len(self.bougiebuffer)         in range (len(self.bougiebuffer),0,-1):             print self.bougiebuffer[i-1].prixfermeture,   self.bougiebuffer[i-1].maximum.value  

i have wrote naturally below not working , returns same value all

bougie.maximum = self.maximum 

you want create copy of maximum() instance assign bougie.maximum attribute; use either copy.copy or copy.deepcopy:

from copy import deepcopy  bougie.maximum = deepcopy(self.maximum) 

you'll need deepcopy if there attributes of maximum mutable; list, dict, set or custom class instance mutable, things integers , strings not.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -