This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: %b does not work, as a binary output formatter
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: BobStein, steven.daprano
Priority: normal Keywords:

Created on 2015-05-02 10:29 by BobStein, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg242388 - (view) Author: Bob Stein (BobStein) Date: 2015-05-02 10:29
`"%b"%42` produces a ValueError exception instead of outputting '101010'

Details here:  http://stackoverflow.com/a/29997703/673991
msg242389 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-05-02 10:57
This is not a bug, since %b is not supported in Python 2, only in Python 3:

https://docs.python.org/2/library/stdtypes.html#string-formatting-operations

No new features will be added to 2.7, so if you need %b you can use Python 3, or in Python 2.7 you can use the newer string format method instead:

py> "{:b}".format(42)
'101010'
msg242390 - (view) Author: Bob Stein (BobStein) Date: 2015-05-02 11:04
Ah, you're right, my mistake.
History
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68300
2015-05-02 11:04:13BobSteinsetmessages: + msg242390
2015-05-02 10:57:22steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg242389

resolution: not a bug
stage: resolved
2015-05-02 10:29:18BobSteincreate