q=open('a+','w')
list1=['10','11','12']
running=True
for i in range(0,9,3):
while running:
linea=open(r'a')
for line in linea:
worda=line.split()
add=worda[i:i+3]
if add==list1:
running=False
else:
q.write(str(add))
print add
i=i+3
else:
print'this loop is over!'
q.write(str(add))
print add
q.close()
运行的结果是
['1','2','3']
['4','5','6']
['7','8','9']
this loop is over!
this loop is over!
this loop is over!
a+文件的结果是
['1','2','3']['4','5','6']['7','8','9']['10','11','12']
怎么使运行结果变成:
['1','2','3']['4','5','6']['7','8','9']['10','11','12']
['4','5','6']['7','8','9']['10','11','12']
['7','8','9']['10','11','12'] |