persistent deque version 4
inhahe
inhahe at gmail.com
Thu May 22 11:20:56 EDT 2008
"inhahe" <inhahe at gmail.com> wrote in message
news:XF1Zj.78287$%15.22707 at bignews7.bellsouth.net...
>
> 4. can someone tell me if the way i'm using the decorator is sane? i've
> never used decorators before. it just seems ridiculous to a) define a
> lambda that just throws away the parameter, and b) define a meaningless
> function to pass to that lambda.
>
I thought about the fact that a decorator is merely syntactic sugar, so it
shouldn't have any closure magic that I can't make myself, and I realized
that I could have done it the following way:
def makefunc(func):
def func2(instance, *args):
result = func(instance, *args)
instance.save()
return result
return func2
for name, func in deque.__dict__.items():
if (not name.startswith("_")) or name in ('__delitem__', '__setitem__'):
setattr(pdeque, name, makefunc(func))
More information about the Python-list
mailing list