mercredi 18 mars 2015

Creating copy of class instance with randomly init variable (python)

I need to initialize an instance of a class with a randomly generated number. I then need to use this instance in several different trials. However, I am having troubles making exact copies of this instance - the randomly generated number will not stay the same. Each copy is generating a new random number.



temp = proc(random.randint(min, max))
tempCpy = copy.copy(temp) #changes on temp interfere with tempCpy
tempCpy = copy.deepcopy(temp) #doesn't start with same random number




Aucun commentaire:

Enregistrer un commentaire