i'm having issue instance attributes being changed unexpectedly when add instances list. new gem instances generate value , name randomly.
self.gem_list = [] in range(self.gem_count): g = gem() print(g) self.gem_list.append(g) print('---') x in self.gem_list: print(x)
gives output:
10 g.p. tiger eye 35 g.p. jasper 10 g.p. rhodochrosite 120 g.p. coral 35 g.p. lapis lazuli 14 g.p. malachite --- 14 g.p. tiger eye 35 g.p. jasper 14 g.p. rhodochrosite 120 g.p. coral 35 g.p. lapis lazuli 14 g.p. malachite
it appears of values being set others, don't understand how happening when i'm doing appending instances created within loop list.
any ideas on may causing this?
i'm wondering if problem lies in assuming each of instances created in loop unique, or rather if may stem elsewhere in code.
edit: here gem class
class gem(): def __init__(self): base_idx = generatebasevalueidx() base_idx, value_mod = modifybasevalue(base_idx) self.value = base_values[base_idx] #determine type of gem self.name, self.group = gemtype(self.value) #modified value self.value.quantity = rounddowntonearest(self.value.quantity * value_mod, 1) def __str__(self): return '{} {} ({})'.format(self.value,self.name,self.group) def __lt__(self,other): return self.value < other.value
Comments
Post a Comment