[Python-Dev] PEP 3127 (Integer Literal Support and Syntax): %o and %b
Eric Smith
eric+python-dev at trueblade.com
Wed Mar 19 05:11:01 CET 2008
I've been double checking the PEP 3127 implementation in py3k and the
backport I did to 2.6. The PEP says this about the % operator:
"The string (and unicode in 2.6) % operator will have 'b' format
specifier added for binary, and the alternate syntax of the 'o' option
will need to be updated to add '0o' in front, instead of '0'."
The %b operator was not added to 3.0, so I'll look into doing that in
both 2.6 and 3.0 (which I opened as issue 2416).
What should be done for '%#o' formatting in 2.6? The above sentence
from the PEP implies it should be modified to add '0o' instead of '0',
even in 2.6. But that seems like a bad idea to me. Maybe it should
stay as-is, but add a -3 warning? Unfortunately, there'd be no way to
change your code to get rid of the warning, short of switching to
str.format() or adding a __future__ import (shudder). In 3.0, '%#o'
already adds the leading '0o'.
More information about the Python-Dev
mailing list