Python Forum
for loop not executing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: for loop not executing (/thread-41921.html)



for loop not executing - Abendrot47 - Apr-09-2024

The two early print statements print but the print statements inside the for loop not. Please advise how to correct my code so the for loop works

    datacompletefile = open("c:/temp/completefile.txt", "w")
    datafinalfile = open("C:/temp/attempt2_final3.txt", "r")
    datafinalreader = datafinalfile.readlines()
    print("in complete area")
    print("xxx")
    for datafinalline in datafinalreader :
        print("datafinalline = ", datafinalline)
        finaltokens = datafinalline.split()
        finalindex = finaltokens[0]
        print('finalindex = ', finalindex)
        for i in alllist :
            if i == [finalindex] :
                print("IN")
                datacompletefile.write(datafinalline)
                datacompletefile.write("\n")     
            else :
                print("NOT IN")
                allcomplete = i + ' 0 0'
                datacompletefile.write(allcomplete)
                datacompletefile.write("\n")     
    datacompletefile.close
    datafinalfile.close



RE: for loop not executing - Gribouillis - Apr-09-2024

(Apr-09-2024, 06:18 PM)Abendrot47 Wrote:     for i in alllist :
We don't know what the variable alllist contains. This is probably the cause of your problems.


RE: for loop not executing - deanhystad - Apr-09-2024

Which for loop? "C:/temp/attempt2_final3.txt" must be empty if the program is not printing "datafinalline = " or 'finalindex = '.