开发者

readline and readlines methods missing from python 3.2?

开发者 https://www.devze.com 2023-03-10 07:11 出处:网络
Did they remove file.readline() and file.readlines() fro开发者_开发百科m python 3.2? If yes what did they replace it with?While there is no file type any more in Python 3.x, the various types in the i

Did they remove file.readline() and file.readlines() fro开发者_开发百科m python 3.2? If yes what did they replace it with?


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).


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


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号