missing Dec_0 and friends from python decimal

July 29, 2010

This fails in py2.4, py2.5.1 and py2.6:

from decimal import Dec_0

But it works in all the other py2.5 subversions!

It seems that exposing Dec_0 (and other similar constants) was considered a bug and “fixed” on Jan 3rd 2009 by renaming it _Dec_0.

Indeed, if I had looked at the source code, I would have seen that Dec_0 was for “internal use only”.

From /usr/lib/python2.5/decimal.py:5159

##### Useful Constants (internal use only) ################################

# Reusable defaults
Inf = Decimal('Inf')
negInf = Decimal('-Inf')
NaN = Decimal('NaN')
Dec_0 = Decimal(0)
Dec_p1 = Decimal(1)
Dec_n1 = Decimal(-1)

Those definitions are missing in py2.4 and py2.5.1, and renamed in py2.6.

Damn: never use undocumented features!

Advertisements

One Response to “missing Dec_0 and friends from python decimal”

  1. Emanuele Zattin Says:

    Ma a che mai ti servirá?? 😀


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: