[Python-Dev] Example for PEP 343
Guido van Rossum
gvanrossum at gmail.com
Wed May 18 00:43:52 CEST 2005
What's the advantage of using two calls to getcontext() vs. saving the
context in a local variable?
On 5/17/05, Raymond Hettinger <python at rcn.com> wrote:
>
>
> > -----Original Message-----
> > From: python-dev-bounces+python=rcn.com at python.org [mailto:python-dev-
> > bounces+python=rcn.com at python.org] On Behalf Of Phillip J. Eby
> > Sent: Tuesday, May 17, 2005 6:06 PM
> > To: Michael Chermside; gvanrossum at gmail.com
> > Cc: python-dev at 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
> > >
> > >@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
> > precision?
>
> Right.
>
> It should save, alter, and then restore:
>
> oldprec = decimal.getcontext().prec
> decimal.getcontext().prec += 2
> yield None
> decimal.getcontext().prec = oldprec
>
>
> Raymond Hettinger
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list