Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print multiple record lines
#4
You can also make a generator, which is cool :p
If your jobs file is massive, and you could potentially have millions of matches, this is something similar to what you'd want to be using.

def find_within(haystack, match, processor=None):
    with open(haystack) as file:
        for line in file:
            if processor:
                line = processor(line)
            if match(line):
                yield line

matches = find_within("jobs.txt",
    lambda job: job[0] == jobname,
    lambda line: line.split("|"))

for match in matches:
    print(match[0], match[1])
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 506 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,208 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 2,393 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,811 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,602 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,034 Dec-02-2020, 07:50 AM
Last Post: Gilush
  How to print string multiple times on new line ace19887 7 5,871 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