Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134887: Add references tolocale module for locale-aware number formatting references instring 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
stefmolin wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromstefmolin:patch-1

Conversation

stefmolin
Copy link

@stefmolinstefmolin commentedMay 29, 2025
edited
Loading

Add references tolocale module for locale-aware number formatting references instring module docs to avoid users thinking that the locale doesn't have a thousands separator for example.

@python-cla-bot
Copy link

python-cla-botbot commentedMay 29, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-appbedevere-appbot added docsDocumentation in the Doc dir skip news labelsMay 29, 2025
@stefmolinstefmolin changed the titleAdd references tolocale module for locale-aware number formatting references instring module docsgh-134888: Add references tolocale module for locale-aware number formatting references instring module docsMay 29, 2025
@stefmolinstefmolin marked this pull request as ready for reviewMay 29, 2025 14:15
@stefmolinstefmolin changed the titlegh-134888: Add references tolocale module for locale-aware number formatting references instring module docsgh-134887: Add references tolocale module for locale-aware number formatting references instring module docsMay 29, 2025
For a locale aware separator, use the ``'n'`` presentation type instead.
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')``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

@stefmolinstefmolinMay 29, 2025
edited
Loading

Choose a reason for hiding this comment

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

There are two other occurrences of "e.g." in this document that pre-date my changes. Would you like me to update those as well?

Copy link
Member

@ericvsmithericvsmith left a comment

Choose a reason for hiding this comment

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

I'm not sure we need to add a reference to setting the locale, since the text already says it's local aware.

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 then 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.

| | digit group separators. |
| | 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 usen, without settingLC_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 anddoesn'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 setsLC_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.

@stefmolin
Copy link
Author

I'm not sure we need to add a reference to setting the locale, since the text already says it's local aware.

While this may be obvious to a core CPython developer, it was not obvious to me or my friend, who is a Python trainer. We have each been using Python for many years. My friend routinely explores parts of the Python documentation to learn new things and share with the community. He found out about then option andshared it on Bluesky, mentioning that the thousands separator may be nothing in your locale. I was excited to try this because I use the comma in the format specifier all the time and sometimes when I teach or show code snippets using this in places that use a different thousands separator, I get asked about this.

When I tried then option, however, it didn't do anything on my machine, which I was shocked to see. I then read through the docs and couldn't see why it wouldn't work. Thestring module docs lack any reference to thelocale module, which at this point I didn't even know existed. I searched on the Internet to see how I could check if my locale was correct, which led me to thelocale module, and I was able to confirm it was set as I would expect. Since the locale was indeed set and the docs say thatn provides locale-aware formatting, I was confused why it wasn't working.

I searched some more to discover why it wasn't using a thousands separator for the format. This time Stack Overflow led me to the real reason behind it not working: I needed to set theLC_NUMERIC category. I seriously doubt that my friend and I are the only people that don't find this obvious, so I made a PR in the hopes that the next person can figure out how to get this working while reading the docs directly, instead of having to troubleshoot it for a while (or just assuming it doesn't work).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ericvsmithericvsmithericvsmith left review comments

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@DangNhutNguyenDangNhutNguyenDangNhutNguyen approved these changes

Assignees
No one assigned
Labels
awaiting core reviewdocsDocumentation in the Doc dirskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@stefmolin@ericvsmith@StanFromIreland@DangNhutNguyen

[8]ページ先頭

©2009-2025 Movatter.jp