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
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
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 =
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)
> ...
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)
> ...
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),
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