8000 Documentation of `n` in the format-specifier should reference locale-setting · Issue #134887 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content < 8000 react-partial partial-name="keyboard-shortcuts-dialog" data-ssr="false" data-attempted-ssr="false" data-react-profiling="false" >
Documentation of n in the format-specifier should reference locale-setting #134887
Open
@stefmolin

Description

@stefmolin

Documentation

I was trying out the option of using n in a format specifier to use locale-aware thousands and decimal separators. I was surprised to see it didn't do anything on my machine, despite locale.getlocale() returning what I expected:

>>> import locale
>>> locale.getlocale()
('en_US', 'UTF-8')
>>> x = 12345
>>> f'{x:n}'
'12345'

I did some more digging and realized I needed to do locale.setlocale(locale.LC_NUMERIC, 'en_US') first, which was neither obvious nor mentioned in the documentation where it introduces the n option:

>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, 'en_US')
>>> x = 12345
>>> f'{x:n}'
'12,345'

I propose adding a mention that the locale.LC_NUMERIC must be set in this section as a helpful cross-reference.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0