[Python-Dev] Decimal FAQ

Facundo Batista facundobatista at gmail.com
Wed May 25 03:56:19 CEST 2005


On 5/22/05, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:

> Some of the private email I've received indicates a need for a decimal
> FAQ that would shorten the module's learning curve.

Nice FAQ, but where we should put it? It's kinda for advanced Decimal users...


> A.  Some users prefer to abbreviate the constructor to just a single
> letter:
> 
> >>> D = decimal.Decimal
> >>> D('1.23') + D('3.45')
> Decimal("4.68")

I'd add something like "However you'll note that this kind of use is
in examples, not in everyday code".


> >>> TWOPLACES = Decimal(10) ** -2

I always wrote it Decimal("0.01"), I think it's more clear.


> A more versatile approach is to create a separate class with Decimal
> objects as attributes (working in a "has-a" capacity rather than an
> "is-a" capacity) and then delegating the arithmetic to the Decimal
> class.

Currency will use the "has-a" method, ;)

.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-Dev mailing list