如何读行直到某一行?

Jos*_*lar 0 python input

我想让我的代码在数字行中读取,并在输入三个零时停止读取.这样的事情:

1231343
13242134
.
.
(more lines of numbers)
.
.
0 0 0(end of the line)
Run Code Online (Sandbox Code Playgroud)

我尝试过做这样的事情,但显然没有用,因为在第一行之前没有声明行.

while line != "0 0 0":
    line = raw_input()
Run Code Online (Sandbox Code Playgroud)

我是否走在正确的轨道上?或者我必须使用别的东西?

fal*_*tru 6

如果满足条件,使用无限循环如何,并使用break语句退出循环:

while True:
    line = raw_input()
    if line == '0 0 0':
        break
    # do something with `line`
Run Code Online (Sandbox Code Playgroud)

或者使用iter哨兵值:

for line in iter(raw_input, '0 0 0'):  # will keep call `raw_input` until meet 0 0 0
    # do something with `line`
Run Code Online (Sandbox Code Playgroud)