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
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
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
-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
, 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
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 --
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
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:
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
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
[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
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.
12 matches
Mail list logo