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
  how to process 12 million record pymach 4 1,299 Aug-01-2024, 07:58 AM
Last Post: Pedroski55
  Print the next 3 lines knob 3 1,293 May-22-2024, 12:26 PM
Last Post: andraee
  Last record in file doesn't write to newline gonksoup 3 1,837 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  How do I stream and record at the same time with arducam? traderjoe 0 1,187 Oct-23-2023, 12:01 AM
Last Post: traderjoe
  How to write the condition for deleting multiple lines? Lky 3 2,228 Jul-10-2022, 02:28 PM
Last Post: Lky
  Delete multiple lines from txt file Lky 6 4,279 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  failing to print not matched lines from second file tester_V 14 9,496 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Display table field on multiple lines, 'wordwrap' 3python 0 2,466 Aug-06-2021, 08:17 PM
Last Post: 3python
  pulling multiple lines from a txt IceJJFish69 3 3,604 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 3,764 Jan-10-2021, 01:50 AM
Last Post: JulyFire

Forum Jump:

User Panel Messages

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