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
#2
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Which for loop? "C:/temp/attempt2_final3.txt" must be empty if the program is not printing "datafinalline = " or 'finalindex = '.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file.write stops while true loop from executing in python3 boonr 3 3,179 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