[英]How to read in lines until a certain line?
我想让我的代码读入数字行,并在输入三个零时停止读入。类似以下内容:
1231343
13242134
.
.
(more lines of numbers)
.
.
0 0 0(end of the line)
我试图做这样的事情,但是显然没有用,因为在第一行之前没有声明line。
while line != "0 0 0":
line = raw_input()
我是否在正确的轨道上? 还是我必须使用其他东西?
假设您正在读取文件
for line in open('path to file'):
if line.strip() == '0 0 0':
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.