[Python-Dev] PEP 460 reboot (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Mon Jan 13 23:11:54 CET 2014


On Mon, 13 Jan 2014 13:56:44 -0800 Guido van Rossum <guido at python.org> wrote:

On Mon, Jan 13, 2014 at 1:40 PM, Antoine Pitrou <solipsis at pitrou.net> wrote: > On Mon, 13 Jan 2014 13:32:28 -0800 > Guido van Rossum <guido at python.org> wrote: >> >> But formatb() feels absurd to me. PEP 460 has neither a precise >> specification or any actual examples, so I can't tell whether the >> intention is that the format string can only contain {...} sequences >> or whether it can also contain "regular" characters. Translating to >> formatb(), my question comes down to the legality of the following >> example: >> >> b'Hello, {}'.formatb(name) # Where name is some bytes object > > Yes, it's allowed. But so is: > > b'\xff\x00{}\x85{}'.formatb(payload, trailer) > > The ASCII bias is because of the bytes literal notation.

But it is nevertheless there. Including arbitrary hex bytes in the ASCII range should be a liability, unless you have memorized the hex codes for ASCII and know that e.g. '\x25' is '%' and '\x7b' is '{'.

That's a good point. I hadn't really thought about that.

The above example (is it from a real protocol?)

(no, it's cooked up)

would be just as clear or clearer written as

b'\xff\x00' + payload + b'\x85' + trailer or b''.join([b'\xff\x00', payload, b'\x85', trailer]) and reasoning about those versions requires no understanding of ASCII.

Fair enough.

Regards

Antoine.



More information about the Python-Dev mailing list