Cult-like behaviour [was Re: Kindness]
Rhodri James
rhodri at kynesim.co.uk
Tue Jul 17 11:21:52 EDT 2018
On 17/07/18 14:14, Marko Rauhamaa wrote:
> Rhodri James <rhodri at kynesim.co.uk>:
>> On 17/07/18 02:17, Steven D'Aprano wrote:
>>> Ah yes, the unfortunate design error that iterating over byte-strings
>>> returns ints rather than single-byte strings.
>>>
>>> That decision seemed to make sense at the time it was made, but turned
>>> out to be an annoyance. It's a wart on Python 3, but fortunately one
>>> which is fairly easily dealt with by a helper function.
>>
>> I don't think I agree with you, but that may just be my heritage as a C
>> programmer. Every time I've iterated over a byte string, I've really
>> meant bytes (as in integers). Those bytes may correspond to ASCII
>> characters, but that's just a detail.
>
> The practical issue is how you refer to ASCII bytes. What I've resorted
> to is:
>
> if nxt == b":"[0]:
> ...
>
> Alternatively, I *could* write:
>
> if nxt in b":":
> ...
>
> What's your favorite way of expressing character constants?
If I'm feeling particularly expansive, I'll do what Peter does and
define COLON or use ord(":") directly. Most of the time though I'll
just use:
if next == 0x3a: # colon
...
But then, as I said, I am mostly a C programmer who happens to write
Python when he gets the chance.
--
Rhodri James *-* Kynesim Ltd
More information about the Python-list
mailing list