Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print multiple record lines
#2
Instead of breaking when you find a match, maybe keep a list of matches?
matches = []
with open("jobs.txt") as jobs:
    for line in jobs:
        record = line.split("|")
        if jobname in record[0]:
            matches.append(record)
if matches:
    for record in matches:
        print(record[0], record[1])
else:
    print("Job name not found")
Reply


Messages In This Thread
Print multiple record lines - by ntigner - Feb-08-2018, 04:15 PM
RE: Print multiple record lines - by nilamo - Feb-08-2018, 04:27 PM
RE: Print multiple record lines - by ntigner - Feb-08-2018, 04:36 PM
RE: Print multiple record lines - by nilamo - Feb-08-2018, 05:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Last record in file doesn't write to newline gonksoup 3 504 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  How do I stream and record at the same time with arducam? traderjoe 0 506 Oct-23-2023, 12:01 AM
Last Post: traderjoe
  How to write the condition for deleting multiple lines? Lky 3 1,204 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 2,392 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  failing to print not matched lines from second file tester_V 14 6,262 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Display table field on multiple lines, 'wordwrap' 3python 0 1,808 Aug-06-2021, 08:17 PM
Last Post: 3python
  pulling multiple lines from a txt IceJJFish69 3 2,633 Apr-26-2021, 05:56 PM
Last Post: snippsat
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,599 Jan-10-2021, 01:50 AM
Last Post: JulyFire
Question How to print multiple elements from multiple lists in a FOR loop? Gilush 6 3,018 Dec-02-2020, 07:50 AM
Last Post: Gilush
  How to print string multiple times on new line ace19887 7 5,865 Sep-30-2020, 02:53 PM
Last Post: buran

Forum Jump:

User Panel Messages

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