prePEP: Money data type
aleax at aleax.it
Tue Oct 21 00:41:24 CEST 2003
Batista, Facundo wrote:
> thousandSeparator = '.'
> decimalSeparator = '.'
> the behaviour is unpredictable (should I generate an exception or
Yes (in face of ambiguity refuse the temptation to guess).
> Why doesn't like to you to
>>>> m = Money(23.3, 2)
>>>> print m
Because more often than not I need to plaster those strings in
some sort of columnar output and those currency sign must NOT
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:-).
More information about the Python-list