简体   繁体   中英

Not entering 'for' loop? Python2.7

For whatever reason, my code is not entering the 'for' loop below in line 85.

The file input_fileA is open. Does anyone have a clue why? This is python 2.7.

 84 if (counter_shiftA == counter_shiftB):
 85     for line in input_fileA:
 86         print line
 87         if shiftBEntryA.strip() in line:
 88             print "Hit a matched line"
 89             counter1 += 1
 90             flag = True
 91             output_file.write(line)
 92         elif shiftEEntryA.strip() in line:
 93             output_file.write(line)
 94             break
 95         elif flag:
 96             output_file.write(line)

You can try adding input_file1.seek(0) before for line in input_file1.readlines(): of line 87 . Since, you mentioned you have called the line before. For more details, you can check discussion here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM