__getattr__ and functions that don't exist

2006-05-25 Thread Erik Johnson
Maybe I just don't know the right special function, but what I am wanting to do is write something akin to a __getattr__ function so that when you try to call an object method that doesn't exist, it get's intercepted *along with it's argument*, in the same manner as __getattr__ intercepts attribut

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Nick Smallbone
Erik Johnson wrote: > Maybe I just don't know the right special function, but what I am wanting to > do is write something akin to a __getattr__ function so that when you try to > call an object method that doesn't exist, it get's intercepted *along with > it's argument*, in the same manner as __ge

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Erik Johnson
Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's slick!", but after playing with this a bit... >>> class Foo: ... def __getattr__(self, attr): ... def intercepted(*args): ... print "%s%s" % (attr, args) ... return intercepted ... >>> f =

Re: __getattr__ and functions that don't exist

2006-05-25 Thread George Sakkis
Erik Johnson wrote: > Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's > slick!", but after playing with this a bit... > > >>> class Foo: > ... def __getattr__(self, attr): > ... def intercepted(*args): > ... print "%s%s" % (attr, args) > ...

Re: __getattr__ and functions that don't exist

2006-05-25 Thread Ben Cartwright
Erik Johnson wrote: > Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's > slick!", but after playing with this a bit... > > >>> class Foo: > ... def __getattr__(self, attr): > ... def intercepted(*args): > ... print "%s%s" % (attr, args) > ...

Re: __getattr__ and functions that don't exist

2006-05-26 Thread bruno de chez modulix en face
class Parrot(object): class _dummy(object): def __init__(self, obj, name): self.name = name self.obj = obj def __call__(self, *args, **kw): print "dummy %s for %s" % (self.name, self.obj) print "called with %s - %s" % (str(args),

Re: __getattr__ and functions that don't exist

2006-05-26 Thread Bruno Desthuilliers
Erik Johnson a écrit : (snip) > I was thinking it would be clean to maintain an interface where you > could call things like f.set_Spam('ham') and implement that as self.Spam = > 'ham' If all you want to do is to assign 'ham' to self.spam, just do it - no need for a setter. And if you worry