【发布时间】:2017-04-21 17:36:47
【问题描述】:
我在这里寻找了几个小时的解决方案,但找不到。也许有人可以帮助我或指出类似的问题?
我在 while 循环中有一个函数。该函数遍历文本文件中的每一行:
def parser():
for line in f:
print(line)
f = open('textfile.txt', 'r')
count = 0
while count < 7:
parser()
count += 1
print(count)
我的输出如下:
text file line 1
text file line 2
text file line 3
1
2
3
4
5
6
我最初的目标是在每次 +1 后再次调用该函数:
text file line 1
text file line 2
text file line 3
1
text file line 1
text file line 2
text file line 3
2
text file line 1
text file line 2
text file line 3
3
...等等。
抱歉,如果这实际上是重复的,并提前感谢!
【问题讨论】:
标签: python python-2.7 while-loop