Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80962 > unrolled thread
| Started by | dieter <dieter@handshake.de> |
|---|---|
| First post | 2014-11-17 08:19 +0100 |
| Last post | 2014-11-17 08:19 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: encode and decode builtins dieter <dieter@handshake.de> - 2014-11-17 08:19 +0100
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-11-17 08:19 +0100 |
| Subject | Re: encode and decode builtins |
| Message-ID | <mailman.15948.1416208766.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web