8000 gh-134887: Add references to `locale` module for locale-aware number formatting references in `string` module docs by stefmolin · Pull Request #134888 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134887: Add references to locale module for locale-aware number formatting references in string module docs #134888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rephrasing changes per review comments
  • Loading branch information
stefmolin committed May 29, 2025
commit 9223d7315d59d2ef1a60f7ecd3c25d2c9942e07e
19 changes: 12 additions & 7 deletions Doc/library/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,10 @@ of a number respectively. It can be one of the following:
| | this option is not supported. |
+---------+----------------------------------------------------------+

For a locale-aware separator, use the ``'n'`` presentation type instead. Note
that the locale setting for numeric values must first be set using the
:mod:`locale` module, *e.g.,* ``locale.setlocale(locale.LC_NUMERIC, 'en_US')``.
For a locale-aware separator, use the ``'n'`` presentation type instead.
Note that the locale setting for numeric values must first be set using
the :mod:`locale` module, for example,
``locale.setlocale(locale.LC_NUMERIC, 'en_US')``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why refer to this here? At most it just belongs in the n section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was troubleshooting why this wasn't working for me, I searched this page in the docs for "locale aware" and "locale-aware" – this was the only hit, so I put this here as well to make sure that all spots a person may learn about this in the docs include all the information to use it directly. Most people won't read the entire page in the docs before using something.


.. versionchanged:: 3.1
Added the ``','`` option (see also :pep:`378`).
Expand Down Expand Up @@ -519,8 +520,10 @@ The available integer presentation types are:
+---------+----------------------------------------------------------+
| ``'n'`` | Number. This is the same as ``'d'``, except that it uses |
| | the current locale setting to insert the appropriate |
| | digit group separators, provided that the locale has |
| | been properly set (see the :mod:`locale` module). |
| | digit group separators. Note that the default locale is |
| | not the system locale, and therefore, you must set, at a |
| | minimum, the ``LC_NUMERIC`` category (see the |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true, is it? I'm referring to the wording "must set": shouldn't it be "can set".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my machine, nothing happens if I use n, without setting LC_NUMERIC, so it is "must set" for me. I'm happy to adjust the wording if there are cases where it is set, but I haven't seen it.

FWIW, I'm seeing that the C locale seems to be very minimal and doesn't have a thousands separator. Since that is what the default is, instead of the system locale, the thousands separator won't be set until the user sets LC_NUMERIC, meaning it is "must set" for everyone. I'm new to the C locale as well though, so let me know if that isn't the case.

| | :mod:`locale` module for more information). |
+---------+----------------------------------------------------------+
| None | The same as ``'d'``. |
+---------+----------------------------------------------------------+
Expand Down Expand Up @@ -603,8 +606,10 @@ The available presentation types for :class:`float` and
| ``'n'`` | Number. This is the same as ``'g'``, except that it uses |
| | the current locale setting to insert the appropriate |
| | digit group separators for the integral part of a |
| | number, provided that the locale has been properly set |
| | (see the :mod:`locale` module). |
| | number. Note that the default locale is not the system |
| | locale, and therefore, you must set, at a minimum, the |
| | ``LC_NUMERIC`` category (see the :mod:`locale` module |
| | for more information). |
+---------+----------------------------------------------------------+
| ``'%'`` | Percentage. Multiplies the number by 100 and displays |
| | in fixed (``'f'``) format, followed by a percent sign. |
Expand Down
Loading
0