Did they remove file.readline() and file.readlines() from python 3.2? If yes what did they replace it with?
Asked
Active
Viewed 8,265 times
4 Answers
4
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)
.

Sven Marnach
- 574,206
- 118
- 941
- 841
2
Here is the documentation (well, tutorial) for Python 3.2.
readline
and readlines
are still a part of Python.

unutbu
- 842,883
- 184
- 1,785
- 1,677
1
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).

isakkarlsson
- 1,111
- 9
- 13
0
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.