[Python-3000] Immutable bytes -- looking for volunteer

Gregory P. Smith greg at krypto.org
Thu Sep 27 07:06:35 CEST 2007


On 9/26/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>
> > However there's quite a bit of Python 2.x code around that manipulates
> > *bytes* in the guise of 8-bit strings, and it uses tests like "if s[0]
> > == 'x': ..." frequently. This can of course be rewritten using a
> > slice, but not so easily when you're looping over bytes:
> >
> >   for b in bb:
> >     if b == b'x': ...
>
> Would it make anything easier if there were a character
> literal?
>
>    for b in bb:
>      if b == c'x': ...
>
> where c'x' is another way of writing ord(b'x').
>
> An advantage of this is that it would make Py3k compatible
> with Pyrex, which already has c'x' literals. :-)

My gut feeling on this is first "neat" but then "eew."  There should
not be multiple ways to write something so simple and letter'' syntax
we already use for b'' s'' u'' r'' and such already annoys me as ugly.
 However that syntax is already established so maybe its okay.

Should it be i'x' instead of c'x' since the result is an int?  i'x'
might look odd in some fonts?

Writing org(b'x') is ugly.

Would a special case in the b'x' comparison tests that knows how to
compare a len==1 bytes (mutable or not) object to an integer be
reasonable or just alternately confusing?

 b'x' == ord(b'x')
 b'x' > 65

Could that lead to people wanting to treat len==1 bytes objects like
tiny ints and use them in math (do *not* allow that)?

And if we did that what would a bytes len!=1 comparison to an integer
do?  return False as it currently does i'd hope.

-gps


More information about the Python-3000 mailing list