Phillip J. Eby wrote: > Actually, it's fairly simple to write a generator decorator using > context.swap() that saves and restores the current execution state > around next()/send()/throw() calls, if you prefer it to be the > generator's responsibility to maintain such context.
Yeah, I also realised there's a fairly obvious solution to my decimal.Context "problem" too: def iter_sin(iterable): orig_ctx = decimal.getcontext() with orig_ctx as ctx: ctx.prec += 10 for r in iterable: y = sin(r) # Very high precision during calculation with orig_ctx: yield +y # Interim results have normal precision # We get "ctx" back here # We get "orig_ctx" back here That is, if you want to be able to restore the original context just *save* the damn thing. . . Ah well, chalk up the __suspend__/__resume__ idea up as another case of me getting overly enthusiastic about a complex idea without looking for simpler solutions first. It's not like it would be the first time ;) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com