Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21154
| Date | 2012-03-02 15:49 -0800 |
|---|---|
| From | Ethan Furman <ethan@stoneleaf.us> |
| Subject | Re: A possible change to decimal.Decimal? |
| References | <15610330.329.1330728373676.JavaMail.geo-discussion-forums@ynlw24> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.358.1330734881.3037.python-list@python.org> (permalink) |
Jeff Beardsley wrote:
> HISTORY:
>
> 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
> Decimal(Decimal())
>
> reload(decimal)
>
> #this fails before patching, but works fine afterwards
> Decimal(Decimal())
>
Patching decimal.py to make it work with reload() is probably not going
to happen.
What you should be doing is:
import decimal
from decimal import Decimal
reload(decimal)
Decimal = decimal.Decimal # (rebind 'Decimal' to the reloaded code)
~Ethan~
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A possible change to decimal.Decimal? Jeff Beardsley <jbeard565@gmail.com> - 2012-03-02 14:46 -0800
Re: A possible change to decimal.Decimal? Ethan Furman <ethan@stoneleaf.us> - 2012-03-02 15:49 -0800
Re: A possible change to decimal.Decimal? "A. Lloyd Flanagan" <A.Lloyd.Flanagan@gmail.com> - 2012-03-04 04:37 -0800
Re: A possible change to decimal.Decimal? "A. Lloyd Flanagan" <A.Lloyd.Flanagan@gmail.com> - 2012-03-04 04:37 -0800
Re: A possible change to decimal.Decimal? Ethan Furman <ethan@stoneleaf.us> - 2012-03-04 07:38 -0800
Re: A possible change to decimal.Decimal? Ethan Furman <ethan@stoneleaf.us> - 2012-03-04 07:44 -0800
csiph-web