A possible change to decimal.Decimal?
ethan at stoneleaf.us
Sat Mar 3 00:49:39 CET 2012
Jeff Beardsley wrote:
> In using python 2.7.2 for awhile on a web project (apache/wsgi web.py), I discovered a problem in using decimal.Decimal. A short search revealed that many other people have been having the problem as well, in their own apache/wsgi implementations (django, mostly), but I found no real solutions among the posts I read. So I did some experimentation of my own.
> The following code will break unexpectedly on standard python2.7 (and earlier) because of the way that isinstance fails after reload() (which is called by both of the above web frameworks).
> This is the error: TypeError("Cannot convert %r to Decimal" % value)
> THE TEST CODE
> import decimal
> from decimal import Decimal
> #this works
> #this fails before patching, but works fine afterwards
Patching decimal.py to make it work with reload() is probably not going
What you should be doing is:
from decimal import Decimal
Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code)
More information about the Python-list