[Python-Dev] PEP 461 updates

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Jan 16 04:54:06 CET 2014


Glenn Linderman wrote:
> 
> x = 354
> b"%c" % x
> 
> Is this an intended exception to the overriding principle?

I think it's an unavoidable one, unless we want to
introduce an "integer in the range 0-255" type. But
that would just push the problem into another place,
since

    b"%c" % byte(x)

would then blow up on byte(x) if x were out of
range.

If you really want to make sure it won't crash, you
can always do

   b"%c" % (x & 0xff)

or whatever your favourite method of mangling out-
of-range ints is.

-- 
Greg


More information about the Python-Dev mailing list