How to wrap a class's methods?
rbt
rbt at athop1.ath.vt.edu
Sun Feb 20 08:36:13 EST 2005
Jeff Shannon wrote:
> You could probably also do this as a factory function, rather than as a
> class (also untested!):
>
> def Wrapper(func):
> def wrapped(self, *args, **kwargs):
> s, r = func(self, *args, **kwargs)
> if s != 'OK':
> raise NotOK((s,r))
> return r
> return wrapped
>
> I believe that this will be semantically almost equivalent, but
> conceptually slightly simpler.
>
> Jeff Shannon
This is a nice example. I have used sub-functions (functions within
functions) recently with some code, but I've wondered how proper it is
to do this. Is this type of thing frowned upon?
More information about the Python-list
mailing list