[英]readline and readlines methods missing from python 3.2?
Did they remove file.readline() and file.readlines() from python 3.2?他们是否从 python 3.2 中删除了file.readline()和file.readlines() ? 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()
.虽然 Python 3.x 中不再有
file
类型,但io
模块中替换旧file
类型的各种类型仍然支持f.readline()
和f.readlines()
。 You actually don't need those methods, though, since they can be substituted by next(f)
and list(f)
.不过,您实际上并不需要这些方法,因为它们可以用
next(f)
和list(f)
代替。
Here is the documentation (well, tutorial) for Python 3.2.这是 Python 3.2 的文档(嗯,教程)。
readline
and readlines
are still a part of Python. readline
和readlines
仍然是 Python 的一部分。
No they did not.不他们没有。
f = open("file", "r")
f.readlines()
is working for me, Python 3.2.为我工作,Python 3.2。
EDIT: it produces an io object (not file).编辑:它产生一个 io object (不是文件)。
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.
看来现在必须明确导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.