prePEP: Money data type
Alex Martelli
aleax at aleax.it
Mon Oct 20 18:41:24 EDT 2003
Batista, Facundo wrote:
...
> thousandSeparator = '.'
> decimalSeparator = '.'
>
> the behaviour is unpredictable (should I generate an exception or
> something?)
Yes (in face of ambiguity refuse the temptation to guess).
> Why doesn't like to you to
>
>>>> m = Money(23.3, 2)
>>>> print m
> $23.30
Because more often than not I need to plaster those strings in
some sort of columnar output and those currency sign must NOT
float:
$ 12.34
$ 4989.12
$ 0.88
good,
$12.34
$4989.12
$0.88
BAD (VERY VERY bad). PLUS: I normally need to use the
INTERNATIONAL symbol -- that '$' means totally different
currencies in the US, HK, etc, which is why the intl symbol
is USD, HKD, etc.
So, if a $ is pasted in front I need to go to the trouble
of taking it out anyway, etc.
A 'format' method could take optional arguments specifying which
locale to use, whether to use money or basic conventions,
international or basic ones, etc. THAT would be of some use,
of course. A __str__ method cannot take such arguments,
and IMHO should therefore default to simplicity -- just
'12.34' (so I can use a '$%8s' % m to get the kind of format
shown in the above columnar output).
No objection to subclasses ADDING functionality such as
the locale-appropriate formatting in __str__, but I think
the base class should default to simplicity. Subclasses
can more easily add features than take them away:-).
Alex
More information about the Python-list
mailing list