[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3
Chris Lasher
chris.lasher at gmail.com
Thu Sep 11 08:39:16 CEST 2014
On Wed, Sep 10, 2014 at 6:50 PM, Stephen J. Turnbull <stephen at xemacs.org>
wrote:
> Chris Lasher writes:
>
> > Okay, but a definite -1e6 from me on making my Python interpreter do
> this:
> >
> > >>> my_packed_bytes = struct.pack('ffff', 3.544294848931151e-12,
> > 1.853266900760489e+25, 1.6215185358725202e-19, 0.9742483496665955)
> > >>> my_packed_bytes
> > b'Why, Guido? Why?'
>
> If you actually have a struct, why aren't you wrapping
> your_packed_bytes in a class that validates the struct and displays it
> nicely formatted? Or, alternatively, simply replaces __repr__?
>
The point was to demonstrate that although text must be represented by
bytes, not all bytes represent text. I have the bytes from four 32-bit
floating point numbers, but repr() displays these bytes as ASCII
characters. It looks like I wrote "Why, Guido? Why?" illustrating how
implicit behavior that's "usually helpful" can be rather unhelpful.
Explicitly showing the hexadecimal values is always accurate, because bytes
are always bytes.
> Your judgment doesn't rule, and it definitely doesn't have a weight of
> 1e6.
I meant the "-1e6" as a cheeky response, not as a reflection of the
importance of my opinions or ideas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140910/6cf89b68/attachment.html>
More information about the Python-ideas
mailing list