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 blo

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)

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 >> ch

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 Raymond Hettinger
> 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 of the current context would be sufficient. The sin() example is correct. The precision is changed and restored in the current context. H

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 > re

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 para

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: http://mail.python.org/mailman/options/python-dev/arc

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Delaney, Timothy C (Timothy)
Bob Ippolito wrote: >> One more thought: Rather than just saving the precision, it is >> likely wiser, safer, and more general to just save and restore the >> whole context and let the wrapped block only work with a copy. >> >> oldcontext = decimal.getcontext() >> newcontext = oldcontext

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Bob Ippolito
On May 17, 2005, at 9:02 PM, Raymond Hettinger wrote: >>> 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 presentati

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

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 -- t

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Guido van Rossum
TECTED] 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/2005 -0700, Michael Chermside wrote: &g

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

Re: [Python-Dev] Example for PEP 343

2005-05-17 Thread Phillip J. Eby
At 02:42 PM 5/17/2005 -0700, Michael Chermside wrote: ># = SAMPLE #1: increasing precision during a sub-calculation = > >import decimal > >@do_template >def with_extra_precision(places=2): > "Performs nested computation with extra digits of precision." > decimal.getcontext().prec +

[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 allow