On 9/4/11 11:47 PM, Kristofer Tengström wrote: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. The code looks like this: > > --------------------------------------------- > > class A: > sub = dict()
You are sharing this single "sub" dictionary with all instances of your
A class.
If you want to define instance-specific attributes, define them in the
__init__ method, like so:
class A:
def __init__(self):
self.sub = dict()
def sub_add(self, cls):
obj = cls()
self.sub[obj.id] = obj
--
Stephen Hansen
... Also: Ixokai
... Mail: me+list/python (AT) ixokai (DOT) io
... Blog: http://meh.ixokai.io/
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list
