Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正如标题所说,我想用一个简单的命令让 Python 读取文本文件的下一行。 例如这样的:
users = open("C:\\Users\\Tharix\\Desktop\\test.txt",mode="r") line = test.readline(20) print(line) line.next() #Or something similar print(line)
(PS:我不知道这有帮助,但我使用的是 Python 3.3.2 版本) 谢谢 :)
只需遍历文件对象:
with open("C:\\Users\\Tharix\\Desktop\\test.txt", mode="r") as users: for line in users: print(line)
请注意,在 py3.x中iter.next()已重命名为iter.__next__()next(iter)
iter.next()
iter.__next__()
next(iter)