decimal point character

Ben Finney bignose-hates-spam at and-benfinney-does-too.id.au
Wed Mar 3 18:02:06 EST 2004


On Wed, 3 Mar 2004 23:58:36 +0100, Bror Johansson wrote:
> Is there a way to 'configure' the built-in conversion function float() to
> accept '.' (dot) as decimalpartdelimiter when executing in an
> anglo-american-language environment and to accept ',' (comma) when executing
> in a language environment where that character is used for the same purpose?

The word you want, rather than "environment", is "locale".  The issue of
decimal point separator is one of the "locale conventions", queried via
locale.localeconv().

    >>> import locale
    >>> locale.getlocale()
    (None, None)
    >>> locale.getdefaultlocale()
    ['en_AU', 'utf']

    >>> locale.localeconv()['decimal_point']
    '.'
    >>> locale.localeconv()['mon_decimal_point']
    ''

    >>> locale.localeconv()
    {'mon_decimal_point': '', 'int_frac_digits': 127, 'p_sep_by_space':
    127, 'frac_digits': 127, 'thousands_sep': '', 'n_sign_posn': 127,
    'decimal_point': '.', 'int_curr_symbol': '', 'n_cs_precedes': 127,
    'p_sign_posn': 127, 'mon_thousands_sep': '', 'negative_sign': '',
    'currency_symbol': '', 'n_sep_by_space': 127, 'mon_grouping': [],
    'p_cs_precedes': 127, 'positive_sign': '', 'grouping': []}

Read about what each of these convention values mean:

    <http://www.python.org/doc/lib/module-locale.html>

-- 
 \           "Military justice is to justice what military music is to |
  `\                                          music."  -- Groucho Marx |
_o__)                                                                  |
Ben Finney <http://bignose.squidly.org/>



More information about the Python-list mailing list