Nathan Harmston a écrit : > Hi, > > I guess my description was a bit rubbish in retrospec, I dont even > think the title of my email made sense....it doesnt to me now: > > class Manager(object): > def __init__(self): > pass > def dosomething(self): > return "RESULTS" > > class Foo(object): > def __init__(self): > self.a = "NEE" > > What I m trying to do is end up with the following syntax: > > f = Foo() # instantiates a Foo object > g= Foo.objects.dosomething() # returns "RESULTS" > > The best way I ve found of doing this is overriding new > > class Foo(object): > def __new__(cls, *args, **kw): > cls.objects = Manager() >
You're obviously overcomplexifying things here... # the canonical pythonic way class Foo(object): objects = Manager() def __init__(self): self.a = "NEE" # the monkeypatch way class Foo(object): def __init__(self): self.a = "NEE" Foo.objects = Manager() HTH -- http://mail.python.org/mailman/listinfo/python-list