Difference between io.open vs open in python
Situation in Python3 according to the docs:
io.open(file, *[options]*)
This is an alias for the builtin open() function.
and
While the builtin open() and the associated io module are the recommended approach for working with encoded text files, this module [i.e. codecs] provides additional utility functions and classes that allow the use of a wider range of codecs when working with binary files
(bold and italics are my edits)
Comments
-
alvas almost 2 years
In the past, there's
codecs
which got replaced byio
. Although it seems like it's more advisable to useio.open
, most introductory python classes still teachesopen
.There's a question with Difference between open and codecs.open in Python but is
open
a mere duck-type ofio.open
?If not, why is it better to use
io.open
? And why is it easier to teach withopen
?In this post (http://code.activestate.com/lists/python-list/681909/), Steven DAprano says that the built in
open
is using theio.open
in the backend. So should we all refactored our code to useopen
instead ofio.open
?Other than backward compatibility for py2.x, are there any reason to use
io.open
instead ofopen
in py3.0?