Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80860 > unrolled thread
| Started by | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| First post | 2014-11-16 18:50 +1100 |
| Last post | 2014-11-16 18:50 +1100 |
| 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 Ben Finney <ben+python@benfinney.id.au> - 2014-11-16 18:50 +1100
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-11-16 18:50 +1100 |
| Subject | Re: encode and decode builtins |
| Message-ID | <mailman.15873.1416124257.18130.python-list@python.org> |
Garrett Berg <googberg@gmail.com> writes: > I made the switch to python 3 about two months ago, and I have to say > I love everything about it, *especially* the change to using only > bytes and str (no more unicode! or... everything is unicode!) As > someone who works with embedded devices, it is great to know what data > I am working with. THanks! It is great to hear from people directly benefiting from this clear distinction. > 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() Why are you in a position where ‘data’ is not known to be bytes? If you want ‘unicode’ objects, isn't the API guaranteeing to provide them? > This is tedious and breaks the pythonic method of not caring about > what your input is. I wouldn't call that Pythonic. Rather, in the face of ambiguity (“is this text or bytes?”), Pythonic code refuses the temptation to guess: you need to clarify what you have as early as possible in the process. > If I expect that my input can always be decoded into valid data, then > why do I have to write this? I don't know. Why do you have to? -- \ “God was invented to explain mystery. God is always invented to | `\ explain those things that you do not understand.” —Richard P. | _o__) Feynman, 1988 | Ben Finney
Back to top | Article view | comp.lang.python
csiph-web