[Python-Dev] Python 3.x and bytes
"Martin v. Löwis"
martin at v.loewis.de
Sun Jun 12 19:34:42 CEST 2011
> # constants
>
> EOH = b'\r'[0]
> CHAR = b'C'[0]
> DATE = b'D'[0]
> FLOAT = b'F'[0]
> INT = b'I'[0]
> LOGICAL = b'L'[0]
> MEMO = b'M'[0]
> NUMBER = b'N'[0]
>
> This is not beautiful code.
In this case, I think the intent would be better captured with
def ASCII(c):
return c.encode('ascii')
EOH = ASCII('\r') # 0D
CHAR = ASCII('C') # 43
DATE = ASCII('D') # 44
FLOAT = ASCII('F') # 46
INT = ASCII('I') # 49
LOGICAL = ASCII('L') # 4C
MEMO = ASCII('M') # 4D
NUMBER = ASCII('N') # 4E
This expresses the intent that a) these are really byte values,
not characters, and b) the specific choice of byte values was motivated
by ASCII.
Regards,
Martin
More information about the Python-Dev
mailing list