本文介绍了如何在循环中多次执行该函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#The dictionary:
f = open("glossary.txt", "r")
num_lines = sum(1 for line in open("glossary.txt"))
def readLines():
global my_glossary
global line
global words
global f
f = open("glossary.txt", "r")
line = f.readline()
words = line.split(",")
my_glossary = {}
my_glossary[words[0]]=words[1]
line = f.readline()
words = line.split(",")
my_glossary[words[0]]=words[1]
while num_lines > 0:
readLines()
num_lines -=1
我试图获得这个while循环来执行多次上面的函数,与文本文件中的行数相关。在文本文件中我有4行,但只有两行使用我的全部代码,我计划在将来为此程序添加更多行到文本文件中...提前感谢
I am trying to get this while loop to execute the function above it multiple times in correlation to the number of lines in the text file. In the text file I have 4 lines but only two work with my full length of code and I plan on adding lots more lines to the text file in the future for this program.....thanks in advance
推荐答案
这篇关于如何在循环中多次执行该函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!