read(1) returns string of length 2

Skip Montanaro skip at pobox.com
Wed Nov 24 07:20:34 EST 2004


    wolfgang> I'm trying to read (japanese) chars from a file. While doing
    wolfgang> so I encounter that a char with length 2 is returned. Is this
    wolfgang> to be expected or is there something wrong?

I believe it's to be expected.  You opened the file with codecs.open(), so
your basic unit of operation will be a Unicode character, not a byte.

    wolfgang> My naive assumption was that f.read(1) returns always a char
    wolfgang> of length 1 (or zero).

If you simply used the builtin open() to open the file that would be true.

Skip




More information about the Python-list mailing list