Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:43:58+00:00 2026-06-02T05:43:58+00:00

I have test results in a log file that are formatted like: useless info

  • 0

I have test results in a log file that are formatted like:

useless info

useless info

======================

useful info

useful info

======================

test success

The number of lines in each section can vary, so I want to check for the first appearance of the double equal character ‘==’ and read that line until the end of the file into a string. Currently I’m using the following code to read the whole file into the string.

with open ("Report.txt", "r") as myfile:
    data = myfile.read()

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:44:00+00:00Added an answer on June 2, 2026 at 5:44 am
    useful = []
    with open ("Report.txt", "r") as myfile:
        for line in myfile:
            if "===" in line:
                break
        for line in myfile:
            useful.append(line)
    a_string = "".join(useful)
    

    I would however prefer to hide it away in a generator, like this:

    def report_iterator():
        with open ("Report.txt", "r") as myfile:
            for line in myfile:
                if "===" in line:
                    break
            for line in myfile:
                yield line
    
    for line in report_iterator():
        # do stuff with line
    

    All the filtering and nitpicking is done in the generator function, and you can separate the logic of “filtering input” from the logic of “working with the input”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test file that has many lines, each line looks something like:
I have a table which stores test results like this: user | score |
I have a test file that contains tests taking quite a lot of time
I have a log file that is not more than 10KB (File size can
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have 2 test and 1 production server. In my global.asax file - I
I have a program that is able to retrieve sections/part of a log text
I want to create the search page that search the history of log file.
I have a piece of code that looks like this: downloadsByExtensionCount = defaultdict(int) downloadsByExtensionList
I have a 600MB tab delimited file that needs to be sorted using only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.