are there some special about '\x1a' symbol

John Machin sjmachin at
Tue Jan 13 12:37:58 CET 2009

On Jan 13, 10:12 pm, "sim.sim" <Maksim.Kasi... at> wrote:
> Ah John, thank you for your explanations!
> My first impression was that your comments does not relates to my
> question,
> but I've found new things where I used to think there was nothing.
> Now it is interesting to me how one have to give reasons to use open
> (.., 'r') instead of open(.., 'rb')?
> There is confusing situation when we use open(.., 'r'), are there some
> scenario when we might be confused when we'll use open(.., 'rb')?

Some general rules: if you regard a file as text, open it with "rt" --
the "t" is redundant but gives you and anyone else who reads your code
that assurance that you've actually thought about it. Otherwise you
regard the file as binary, and open it with "rb". The distinction was
always important on Windows because of the special handling of
newlines and '\x1a') but largely unimportant on *x boxes. With Python
3.0, it is important for all users to specify the mode that they
really need: 'b' files read and write bytes objects whereas 't' files
read and write str objects, have the newline etc changes, and need an
encoding to decode the raw bytes into str (Unicode) objects -- and you
can't use bytes objects directly with a 't' file nor str objects
directly a 'b' file.


More information about the Python-list mailing list