Cult-like behaviour [was Re: Kindness]

Peter Otten __peter__ at web.de
Tue Jul 17 10:19:58 EDT 2018


Marko Rauhamaa wrote:

> The practical issue is how you refer to ASCII bytes. What I've resorted
> to is:
> 
>       if nxt == b":"[0]:
>           ...

You seem to have the compiler's blessing:
 
>>> def f(c):
...     return c == b":"[0]
... 
>>> import dis
>>> dis.dis(f)
  2           0 LOAD_FAST                0 (c)
              3 LOAD_CONST               3 (58)
              6 COMPARE_OP               2 (==)
              9 RETURN_VALUE

> What's your favorite way of expressing character constants?

Before I've seen your way I would have written

COLON = ord(":")
...
if nxt == COLON:
    ...




More information about the Python-list mailing list