Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80962

Re: encode and decode builtins

From dieter <dieter@handshake.de>
Subject Re: encode and decode builtins
Date 2014-11-17 08:19 +0100
References <CALW7ahxWU_N87oAz0JJoXEiyLO0Erx-YggVmQgggzxST6Ra6XQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15948.1416208766.18130.python-list@python.org> (permalink)

Show all headers | View raw


Garrett Berg <googberg@gmail.com> writes:
> ...
> However, there are times that I do not care what data I am working with,
> and I find myself writing something like:
>
> if isinstance(data, bytes): data = data.decode()

Apparently, below this code, you do care that "data" contains
"str" (not "bytes") -- otherwise, you could simply drop this line.

Note, in addition, that the code above might only work if "data" actually
contains ASCII only bytes (at least in Python 2.x, it would fails
otherwise). To safely decode bytes into unicode, you need to precisely
know the encoding -- something which is not consistent with
"I do not care about what data I am working with".

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: encode and decode builtins dieter <dieter@handshake.de> - 2014-11-17 08:19 +0100

csiph-web