-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Add note in docs regarding uppercase 'X' specifier #19332
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
Conversation
I noticed that when using string format to print hexadecimal numbers like the following: >>> '{:#X}'.format(1234) '0X4D2' I get an uppercase 'X', this is worth mentioning in the docs.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Hi, thanks for this! Definitely worth noting this in the docs. Have you considered simply adding '0X' to the list in the paragraph describing the '#' modifier? I.e.:
|
@taleinat Thanks for you input, I didn't consider this option. On one hand it makes perfect sense to add it where you specified since it's a smaller and simpler change, but on the other hand, I am not sure it's the intuitive location that people will first look at when trying to understand this behavior. How would you suggest to decide what the right solution is? |
I prefer this in the description of the '#' modifier, since it is much more esoteric. Where possible, we should avoid having info about rare edge-cases mixed with info about common cases. And as a core dev, if you make this change, I'd be happy to merge it :) |
I agree with @taleinat 's review. +1 to adding a change here:
If you keep the current patch that explains about upper casing of "0X" prefix along with rest. that's a good addition too. We don't want to give an impression that a format like "0xDEADBEEF" can be returned when using '{:#X}'.format("deadbeef") |
Note that this was closed only due to the renaming of the I still think that this is a worthy improvement to the docs, but can't re-open this PR due to the original branch having been deleted. |
Tal, we could cherry-pick this 12ec96e (I suppose) and create a new PR and merge it. |
@orsenthil, I've already created a new PR for this, please see GH-25941. |
I noticed that when using string format to print hexadecimal numbers like the following:
I get an uppercase 'X', this is worth mentioning in the docs.