How can I tell when a string is in fact a number?

Alex Martelli aleaxit at yahoo.com
Tue Nov 7 10:10:55 EST 2000


"Julio Flores Schwarzbeck" <jflores at codeit.com> wrote in message
news:mailman.973541120.11746.python-list at python.org...
>
> What numeric system uses two dots? ;)

The traditional Italian one does (although they're
differently-spaced).
    1.234.567
is one million, twohundred and thirtyfour thousands,
fivehundred and sixtyseven (decimals, if any,
follow after a _comma_; basically, you can think
of it as having the dot and comma roles exchanged
wrt traditional British usage).

Remember you need to pass the third argument as
true to locale.format to see this...:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "IT")
'Italian_Italy.1252'
>>> locale.format("%d", 12345678,1)
'12.345.678'
>>> locale.format("%12.2f", 12345678.9,1)
' 12.345.678,90'
>>>

Without that '1' at the end, you wouldn't see the
dots, since 'grouping' defaults to 0 (that's the
third argument to locale.format...).


Alex






More information about the Python-list mailing list