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
#4
well, could not get to sleep without trying it.
It prints just --1 and stops. I'm expecting the first 'for' loop will keep going but it stops.
Should print:
--1
--2
--3
with open("C:/01/file1.txt", 'r') as f:
    with open("C:/01/file2.txt", 'r') as fe:
        for line_f in f:
            #print(f"F1 >{line_f}")
            for line_fe in fe:
                #print(f"F2 >{line_fe}")
                if line_f == line_fe:
                    print(f"-- {line_fe}")
Reply


Messages In This Thread
RE: Do not get how Python iterates over a file - by tester_V - Jan-27-2023, 08:12 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