Python 3 is killing Python

Marko Rauhamaa marko at
Wed Jul 16 12:46:45 CEST 2014

Steven D'Aprano <steve at>:

> Likewise for files: by default, I should be able to do this:
> open("foo.txt", "w").write("foo bar baz")
> and have something sensible happen.

I'd prefer:

   open("foo.txt", "wt").write("foo bar baz")


   open("foo.txt", "w", encoding="utf-8").write("foo bar baz")


   open("foo.txt", "w").write("foo bar baz".encode())

Python 3 really is on a mission to elevate text into the mainstream at
the expense of bytes. I'm guessing this is done primarily to promote the
cross-platform transparency of Python code.

For me, a linux system and network programmer, that layer of frosting
only gets in my way and I need to wash it off.

> Most programming languages I know of default to opening files in text
> mode, not binary mode, and I don't see any strong reason for Python to
> go against the tide there.

In unix and linux, there never was a separate text mode for files. When
you open a file, you open a file -- and stuff bytes in it. There is no
commonly accepted text file encoding. UTF-8 comes close to being a
standard, but I know somebody who sticks to an ISO-8859-1 locale.

> Having len('λ') == 1 is not an advanced text processing feature.

There are (relative rare) occasions where you'd like to treat text as
text. Then, it's nice to be able to move the data on the operating table
with .decode() and when the patient has been sewn back together, you can
release them with .encode().

More often, len(b'λ') is what I want.


More information about the Python-list mailing list