Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
#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


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
Posted
Comments
Sergey Alexandrovich Kryukov 29-Jan-15 11:22am    
Why? Don't you have to do the other way around: iterate through lines inside the frame where you open and close the file? What are you trying to achieve with all that? Don't tell us your goal is to call some function; tell us what are ins and outs; what you are trying to achieve?
—SA
Dylan Forsyth 29-Jan-15 11:32am    
I am using tkinter to try achieve getting the first word inside the txt file (bug) then its definition next to it. The definition gets printed out below you input of the first word. I am trying to get it to analyse all of the lines in the txt file but no more/less so it doesn't return any errors or not read the whole file...I would prefer to get the whole file read at once though

1 solution

I just provided the solution in your original question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900