A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-June/111882.html below:

[Python-Dev] Python 3.x and bytes

[Python-Dev] Python 3.x and bytes [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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4