Re: [Python-Dev] Example for PEP 343

2005-05-18 Thread Nick Coghlan
Guido van Rossum wrote: Anyway, perhaps we should provide this most general template: @do_template def with_decimal_context(): oldctx = decimal.getcontext() newctx = oldctx.copy() decimal.setcontext(newctx) yield newctx decimal.setcontext(oldctx) To

Re: [Python-Dev] Example for PEP 343

2005-05-18 Thread Michael Chermside
Phillip writes: @do_template def with_extra_precision(places=2): Performs nested computation with extra digits of precision. decimal.getcontext().prec += 2 yield None decimal.getcontext().prec -= 2 Won't this do the wrong thing if something within the block alters the

[Python-Dev] Example for PEP 343

2005-05-17 Thread Michael Chermside
In PEP 343 Guido writes: 8. Another use for this feature is the Decimal context. It's left as an exercise for the reader. (Mail it to me if you'd like to see it here.) Here are two such examples. Pick your favorite for the PEP. PS: Writing this helped convince me that

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Raymond Hettinger
-Original Message- From: [EMAIL PROTECTED] [mailto:python-dev- [EMAIL PROTECTED] On Behalf Of Phillip J. Eby Sent: Tuesday, May 17, 2005 6:06 PM To: Michael Chermside; [EMAIL PROTECTED] Cc: python-dev@python.org Subject: Re: [Python-Dev] Example for PEP 343 At 02:42 PM 5/17

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Guido van Rossum
, May 17, 2005 6:06 PM To: Michael Chermside; [EMAIL PROTECTED] Cc: python-dev@python.org Subject: Re: [Python-Dev] Example for PEP 343 At 02:42 PM 5/17/2005 -0700, Michael Chermside wrote: # = SAMPLE #1: increasing precision during a sub-calculation = import decimal

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Raymond Hettinger
What's the advantage of using two calls to getcontext() vs. saving the context in a local variable? I prefer saving the context in a local variable but that is just a micro-optimization. The presentation with multiple calls to getcontext() was kept just to match the style of the original --

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Raymond Hettinger
What's the advantage of using two calls to getcontext() vs. saving the context in a local variable? I also prefer saving the context in a local variable but that is just a micro-optimization. The presentation with multiple calls to getcontext() was kept just to match the style of the

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Raymond Hettinger
I think you're missing a decimal.setcontext(newcontext) before the yield.. Right. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe:

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Guido van Rossum
On 5/17/05, Raymond Hettinger [EMAIL PROTECTED] wrote: I think you're missing a decimal.setcontext(newcontext) before the yield.. Right. I don't see a call to setcontext() in the sin() example in the library reference. Is that document wrong? I thought that simply modifying the parameters

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Bob Ippolito
On May 17, 2005, at 10:36 PM, Guido van Rossum wrote: On 5/17/05, Raymond Hettinger [EMAIL PROTECTED] wrote: I think you're missing a decimal.setcontext(newcontext) before the yield.. Right. I don't see a call to setcontext() in the sin() example in the library reference. Is that

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Guido van Rossum
[Raymond Hettinger] The sin() example is correct. The precision is changed and restored in the current context. I got that eventually. :-) However, for a general purpose wrapper, it is preferable to make a context copy and then restore the context after the enclosed is run. That guards

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Bob Ippolito
On May 17, 2005, at 11:39 PM, Guido van Rossum wrote: [Raymond Hettinger] However, for a general purpose wrapper, it is preferable to make a context copy and then restore the context after the enclosed is run. That guards against the enclosed block making any unexpected context changes.