If you open a file in text mode in Python 2 you open it to return bytes.
That makes no sense. If it returns bytes, then it's in binary mode. If it were in text mode, it'd return unicode objects. (And please don't say that the difference between "text" and "binary" is solely whether the CRLF-to-LF conversion is enabled or not.)
Unfortunately there are cases now in Python 3 where you cannot be explicit
open has a keyword argument encoding. You can always be explicit.
That does not change that this is how the default API in Python 2 works. It's by far not the only API to open files in 2.x. That however was not the point.
open has a keyword argument encoding. You can always be explicit.
a) people are not. b) not every api supports that. Case in point: filenames, environment variables and argv.
1
u/[deleted] May 26 '14
That makes no sense. If it returns bytes, then it's in binary mode. If it were in text mode, it'd return
unicodeobjects. (And please don't say that the difference between "text" and "binary" is solely whether the CRLF-to-LF conversion is enabled or not.)openhas a keyword argumentencoding. You can always be explicit.