"convert" string to bytes without changing data (encoding)

Chris Angelico rosuav at gmail.com
Thu Mar 29 22:41:31 CEST 2012


On Fri, Mar 30, 2012 at 5:00 AM, Ross Ridge <rridge at csclub.uwaterloo.ca> wrote:
> Sorry, it would've been more accurate to label the flavour of kool-aid
> Chris Angelico was trying to push as "it's impossible ... without
> encoding":
>
>        What is a string? It's not a series of bytes. You can't convert
>        it without encoding those characters into bytes in some way.

I still stand by that statement. Do you try to convert a "dictionary
of filename to open file object" into a "series of bytes" inside
Python? It doesn't matter that, on some level, it's *stored as* a
series of bytes; the actual object *is not* a series of bytes. There
is no logical equivalency, ergo it is illogical and nonsensical to
expect to turn one into the other without some form of encoding.
Python does include an encoding that can handle lists and
dictionaries. It's called Pickle, and it returns (in Python 3) a bytes
object - which IS a series of bytes. It doesn't simply return some
internal representation.

ChrisA



More information about the Python-list mailing list