[Python-ideas] Python 3.x and bytes
ethan at stoneleaf.us
Fri May 20 15:05:37 CEST 2011
Terry Reedy wrote:
> As far as I noticed, Ethan did not explain why he was extracting single
> bytes and comparing to a constant, so it is hard to know if he was even
> using them properly.
The header of a .dbf file details the field composition such as name,
size, type, etc. The type is C for character, L for logical, etc, and
the end of the field definition block is signaled by a CR byte.
So in one spot of my code I (used to) have a comparison
if hdr == b'\x0d': # end of fields
which I have changed to
if hdr == 0x0d:
field_type = hdr
which is now
field_type = chr(hdr)
since the first 127 positions of unicode are ASCII.
However, I can see this silently producing errors for values between 128
and 255 -- consider:
So because my single element access to the byte string lost its bytes
type, I may no longer get the correct result.
More information about the Python-ideas