1
回答
新手入门,望指点。写了个小程序,各位大神给改改。
注册华为云得mate10,2.9折抢先购!>>>   
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']
举报
qiushi19911025
发帖于3年前 1回/112阅
顶部