Reputation: 8745
Did they remove file.readline() and file.readlines() from python 3.2? If yes what did they replace it with?
Upvotes: 3
Views: 8283
Reputation:
I had problems, too. However, when I included an
import readline
at the top of my script, everything worked fine. It appears that it has to be imported explicitly now.
Upvotes: 0
Reputation: 1109
No they did not.
f = open("file", "r")
f.readlines()
is working for me, Python 3.2.
EDIT: it produces an io object (not file).
Upvotes: 1
Reputation: 879371
Here is the documentation (well, tutorial) for Python 3.2.
readline
and readlines
are still a part of Python.
Upvotes: 2
Reputation: 601539
While there is no file
type any more in Python 3.x, the various types in the io
module that replace the old file
type still support f.readline()
and f.readlines()
. You actually don't need those methods, though, since they can be substituted by next(f)
and list(f)
.
Upvotes: 4