nik
nik

Reputation: 8745

readline and readlines methods missing from python 3.2?

Did they remove file.readline() and file.readlines() from python 3.2? If yes what did they replace it with?

Upvotes: 3

Views: 8283

Answers (4)

user2015601
user2015601

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

isakkarlsson
isakkarlsson

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

unutbu
unutbu

Reputation: 879371

Here is the documentation (well, tutorial) for Python 3.2. readline and readlines are still a part of Python.

Upvotes: 2

Sven Marnach
Sven Marnach

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

Related Questions