Numeric data question
Alex Martelli
aleax at aleax.it
Wed Jul 24 13:33:03 EDT 2002
terry wrote:
...
> I'm guessing now (from lack of real experience) that being a
> 'typeless' language that I would be forced into contriving a
> method for handling money such that I could never code something
> straightforwardly like:
> TotalCost = Quantity * UnitCost
> (where Quantity is integer and the others money).
If you were working with a typeless language, that might be the case.
Fortunately, Python is strongly typed, so that's no problem, of
course. This statement would probably be equivalent to
something like:
TotalCost = type(UnitCost).__rmul__(Quantity(
for example (or UnitCost.__class__.__rmul__ if UnitCost was an
instance of an old-fashioned class, but that comes to much the
same thing). Just code your __rmul__ (and __mul__, etc) methods
and voila, whatever numeric type you want is there.
http://starship.python.net/crew/aahz/Decimal.py is an example,
though Aahz still doesn't consider it finished.
> Am I loonie, or is Python just not inherently suitable for
> accounting applications for this reason?
If you're saying that Python is "typeless", then I guess
"loonie" might be applicable, yes.
Alex
More information about the Python-list
mailing list