Python Forum
Do not get how Python iterates over a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do not get how Python iterates over a file
#2
How do you expect to get 4, 5, 6, 7 in the output, when you print just lines from file 1, which end at 3?

I would suggest that you print both lines, just before the if block.

Also, note that you open BOTH files before the 2 loops. In the first iteration of the outer loop, you iterate over whole file2 (the inner loop). At that point you are at the end of file 2 and line_fe=7. There is nothing to iterate any more, so for the next 2 loops in the outer loop, the inner loop does nothing
tester_V likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Do not get how Python iterates over a file - by buran - Jan-27-2023, 07:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Still do not get how Python iterates over a file tester_V 13 3,861 Aug-24-2021, 05:10 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

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