[Python-Dev] bytes type discussion

Fred L. Drake, Jr. fdrake at acm.org
Wed Feb 15 05:23:45 CET 2006

On Tuesday 14 February 2006 22:34, Greg Ewing wrote:
 > Seems to me this is a case where you want to be able
 > to change encodings in the middle of reading the stream.
 > You start off reading the data as ascii, and once you've
 > figured out the encoding, you switch to that and carry
 > on reading.

Not quite.  The proper response in this case is often to re-start decoding 
with the correct encoding, since some of the data extracted so far may have 
been decoded incorrectly.  A very carefully constructed application may be 
able to go back and re-decode any data saved from the stream with the 
previous encoding, but that seems like it would be pretty fragile in 

There may be cases where switching encoding on the fly makes sense, but I'm 
not aware of any actual examples of where that approach would be required.


Fred L. Drake, Jr.   <fdrake at acm.org>

More information about the Python-Dev mailing list