[Python-Dev] Maintenance burden of str.swapcase

Stephen J. Turnbull stephen at xemacs.org
Wed Sep 7 04:15:04 CEST 2011


Antoine Pitrou writes:

 > Bytes objects are often used for partly ASCII strings,

All I can say to that phrase is, "urk, ISO 2022 anyone?"

 > not arbitrary "arrays of bytes". And making indexing of bytes
 > objects return ints was IMHO a mistake.

Bytes objects are not ASCII strings, even though they can be used to
represent them.  The practice of using magic numbers that look like
English words is a useful one, but by the same token, it should not be
too easy to use bytes to represent *text* just because the programmer
doesn't know any words that don't fit into 7*N bits.  With PEP 393,
there isn't even really a space excuse.

AFAICS, anything that should be done with ASCII-punned magic numbers
("protocol tokens", if you prefer) can be done with slices and (ta-da!)
case conversion.  (Sorry, Nick!)  But the components of a bytes object
are just numbers; they are not characters until you've run them
through a codec.


More information about the Python-Dev mailing list