[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 2

Cameron Simpson cs at zip.com.au
Sun Feb 23 13:05:24 CET 2014


On 23Feb2014 12:30, Victor Stinner <victor.stinner at gmail.com> wrote:
> > All the numeric formatting codes (such as ``%x``, ``%o``, ``%e``, ``%f``,
> > ``%g``, etc.) will be supported, and will work as they do for str, including
> > the padding, justification and other related modifiers.
> 
> IMO you should give the exhaustive list here and we should only
> support one formatter for integers: %d. Python 2 supports "%d", "%u"
> and "%i" with "%u" marked as obsolete. Python 3.5 should not
> reintroduce obsolete formatters. If you want to use the same code base
> for Python 2.6, 2.7 and 3.5: modify your code to only use %d. Same
> rule apply for 2to3 tool: modify your source code to be compatible
> with Python 3.

> Please also mention all flags: #, +, -, '0', ' '.

Is this really necessary? Can't one just refer the the str %-formatting
section of the doco? By section and title to make it easy to find.

I think this should just refer the reader to the str %-formatting doco for
the numeric codes and their meanings, along with the flags. Otherwise the PEP
will get unreadable, to no value that I can see.

If we include Nick's equivalent code example, there is no ambiguity
or vagueness.

I'm against restricting to just %d for int too; if the current Python
supports others (eg %o, %x) for str, so should this PEP for bytes.

> > ``%c`` will insert a single byte, either from an ``int`` in range(256), or
> > from
> > a ``bytes`` argument of length 1, not from a ``str``.
> 
> I'm not sure that supporting bytes argument of 1 byte is useful, but
> it should not be hard to implement and may be convinient.

I'm +0.5 for a bytes argument of length 1; while bytes are arrays
of small ints, just as str has no distinct "char" type a bytes has
no distinct byte type. With a string we commonly use s str of length
1 to denote a single character in isolation; the same programming
idioms will get you a bytes of length 1 in situations when you mean
a byte.

> (You forgot "/Uhhhhhhhh" representation (it's an antislah, but I don't
> see the key on my Mac keyboard?).)

My Mac has one above the "return" key. Um, non-English locale? Curious.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

16 October. I also asked Anthea how many mature oaks she thought it
would have taken to build a top-of-the-line ship in Nelson's day. She
guessed ten. The astonishing answer (from Brewer's) is about 3,500 -
900 acres of oak forest. She said, "I wonder what we're doing now that's
as wasteful as that". I said it's still called Defence.
- Brian Eno, _A Year With Swollen Appendices_


More information about the Python-Dev mailing list