On Thu, Jun 19, 2008 at 9:50 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:
> I'm making a few classes for a very simple ORM, where the classes reflect > objects that I'm persisting via pickle. I'd like to add and delete instances > via add() and delete() classmethods, so that the classes can keep track of > the comings and goings of their instances. What you have almost works. Try this: class Model(object): @classmethod def add(cls, *args): inst = cls(*args) cls.instances.append(inst) class File(Model): instances = [] def __init__(self, *args): self.filename = args[0] self.keyword = args[1] File.add('somefilename','keywordforthisfile') print File.instances You have to define instances in each class; a metaclass could do that for you. Anyway I hope this gets you a little farther. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor