Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop not executing
#1
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
Gribouillis write Apr-09-2024, 06:30 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
for loop not executing - by Abendrot47 - Apr-09-2024, 06:18 PM
RE: for loop not executing - by Gribouillis - Apr-09-2024, 06:32 PM
RE: for loop not executing - by deanhystad - Apr-09-2024, 07:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  file.write stops while true loop from executing in python3 boonr 3 3,229 Mar-25-2019, 12:50 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020