Cult-like behaviour [was Re: Kindness]
Roel Schroeven
roel at roelschroeven.net
Mon Jul 16 17:50:12 EDT 2018
Steven D'Aprano schreef op 16/07/2018 2:18:
> On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote:
>
>> Python3 is intrinsically tied to Unicode for string handling. Therefore,
>> the Python programmer is forced to deal with it (in all but trivial
>> cases), rather than given a choice. So I don't understand how I can
>> illustrate my point with Python code since Python won't let me deal with
>> strings without also dealing with Unicode.
>
> Nonsense.
>
> b"Look ma, a Python 2 style ASCII string."
Except for one little difference, which has bitten be me a few times.
Consider this code:
from __future__ import print_function
s = b"Look ma, a Python 2 style ASCII string."
print('First element:', s[0])
Result in Python 2: First element: L
Result in Python 3: First element: 76
Likewise this code:
from __future__ import print_function
for e in b'hello':
print(e, end=', ')
print()
Result in Python 2: h, e, l, l, o,
Result in Python 3: 104, 101, 108, 108, 111,
There are times (encoding/decoding network protocols and other data
formats) when I have a byte string and I want/need to process it like
Python 2 does, and that is the one area where I feel Python 3 make
things a bit more difficult.
--
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
-- Franklin P. Jones
Roel Schroeven
More information about the Python-list
mailing list