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

Jim J. Jewett jimjjewett at gmail.com
Mon Feb 24 22:08:54 CET 2014



Victor Stinner wrote:

>> Will ascii() ever emit an antislash representation?

> Try ascii(chr(0x1fffff)).

In which version?  I get:

    ValueError: chr() arg not in range(0x110000)

> How do you plan to use this output? Write it into a socket or a file?

> When I debug, I use print & logging which both expect text string. So I
> think that b'%a' is useless.

Sad Use Case 1:
There is not yet a working implementation of the file
or wire format.  Either I am still writing it, or the
file I need to parse is coming from a "partner" who
"configured" rather than wrote the original program.

I write (or request that they write) something
recognizable to the actual stream, as a landmark.

Case 1a:  I want a repr of the same object that is
supposedly being represented in the official format,
so I can see whether the problem is bad data or
bad serialization.  

Use Case 2:
Fallback for some sort of serialization format;
I expect not to ever use the fallback in production,
but better something ugly than a failure, let alone
a crash.

Use Case 3:
Shortcut for serialization of objects whose repr is
"good enough".  (My first instinct would probably be
to implement the __bytes__ special method, but if I
thought that was supposed to expose the real data,
as opposed to a serialized copy, then I would go
for %a.)


-jJ

-- 

If there are still threading problems with my replies, please 
email me with details, so that I can try to resolve them.  -jJ



More information about the Python-Dev mailing list