[Python-3000] Fix imghdr module for bytes

Paul Moore p.f.moore at gmail.com
Sun Aug 12 21:19:23 CEST 2007


On 11/08/07, Adam Olsen <rhamph at gmail.com> wrote:
> Try h[0:1] == b'P'.  Slicing will ensure it stays as a bytes object,
> rather than just giving the integer it contains.

Ugh. Alternatively, h[0] == ord('P') should work.

Unless you're writing source in EBCDIC (is that allowed?).

All of the alternatives seem somewhat ugly. While I agree with the
idea that the bytes should be kept clean & simple, we seem to be
finding a few non-optimal corner cases. It would be a shame if the
bytes type turned into a Python 3.0 wart from day 1...

Would it be worth keeping a wiki page of the bytes type "idioms" that
are needed, as people discover them? Putting them all in one place
might give a better feel as to whether there is a real problem to
address.

Paul.


More information about the Python-3000 mailing list