[Python-Dev] Example for PEP 343
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Wed May 18 03:19:35 CEST 2005
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.copy()
>> newcontext.prec += 2
>> yield None
>> decimal.setcontext(oldcontext)
>>
>> This approach defends against various kinds of unruly behavior by the
>> yield target.
>
> I think you're missing a decimal.setcontext(newcontext) before the
> yield..
Seems to me this should be in the standard library ;)
Tim Delaney
More information about the Python-Dev
mailing list