On Sat, Jan 23, 2021 at 09:11:27PM +1100, Chris Angelico wrote:
On the other hand, if we add `open_text()`:
* Replacing open with open_text is easier than adding `, encoding="utf-8"`. * Teachers can teach to use `open_text` to open text files. Students can use "utf-8" by default without knowing about what encoding is.
So `open_text()` can provide better developer experience, without waiting 10 years.
But this has a far worse end goal - two open functions with subtly incompatible defaults, and a big question of "why should I choose this over that".
It has an easy answer: - Are you opening a text file and you don't know about or want to deal with encodings? Use `open_text`. - Otherwise, use `open`. I think that if we moved to an open_text() builtin, it should have the simplest possible signature: open_text(filename, mode='r') If you care about anything beyond that, use `open`.
And if you start using open_text, suddenly your code won't work on older Pythons.
"Using older Pythons" is mostly a concern for library maintainers, not beginners. A few years from now, Python 3.10 will be the oldest version the great majority of beginners will care about, and 3.9 will be as irrelevant to them as 3.4 is to us today. Library maintainers always have to deal with the issue of not being able to use the newest functionality, it doesn't prevent us from adding new functionality. -- Steve