[Python-checkins] python/nondist/peps pep-0343.txt,1.12,1.13
gvanrossum@users.sourceforge.net
gvanrossum at users.sourceforge.net
Wed May 18 04:53:28 CEST 2005
Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23233
Modified Files:
pep-0343.txt
Log Message:
Add a variant of the decimal example.
Index: pep-0343.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0343.txt,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pep-0343.txt 17 May 2005 22:15:50 -0000 1.12
+++ pep-0343.txt 18 May 2005 02:53:26 -0000 1.13
@@ -416,6 +416,20 @@
s += num / fact * sign
return +s
+ An alternative version of the generator saves the entire
+ context instead of just the precision attribute. This is more
+ robust, but also more expensive, making it perhaps the better
+ choice when several attributes are modified together:
+
+ @do_template
+ def with_extra_precision(places=2):
+ oldcontext = decimal.getcontext()
+ newcontext = oldcontext.copy()
+ newcontext.prec += places
+ decimal.setcontext(newcontext)
+ yield None
+ decimal.setcontext(oldcontext)
+
References
[1] http://blogs.msdn.com/oldnewthing/archive/2005/01/06/347666.aspx
More information about the Python-checkins
mailing list