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

  • SEARCH
  • Home
  • 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 9206239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:08:01+00:00 2026-06-18T00:08:01+00:00

Pretty new to Python and have been writing up a script to pick out

  • 0

Pretty new to Python and have been writing up a script to pick out certain lines of a basic log file

Basically the function searches lines of the file and when it finds one I want to output to a separate file, adds it into a list, then also adds the next five lines following that. This then gets output to a separate file at the end in a different funcition.

What I’ve been trying to do following that is jump the loop to continue on from the last of those five lines, rather than going over them again. I thought the last line in the code would solved the problem, but unfortunately not.

Are there any recommended variations of a for loop I could use for this purpose?

def readSingleDayLogs(aDir): 
print 'Processing files in ' + str(aDir)    + '\n'
lineNumber = 0
try:
    open_aDirFile = open(aDir)  #open the log file
    for aLine in open_aDirFile: #total the num. lines in file
        lineNumber = lineNumber + 1
    lowerBound = 0
    for lineIDX in range(lowerBound, lineNumber):          
        currentLine = linecache.getline(aDir, lineIDX)
        if (bunch of logic conditions):
                    issueList.append(currentLine)
                    for extraLineIDX in range(1, 6): #loop over the next five lines of the error and append to issue list
                        extraLine = linecache.getline(aDir, lineIDX+ extraLineIDX) #get the x extra line after problem line
                        issueList.append(extraLine)
                    issueList.append('\n\n')
                    lowerBound = lineIDX
  • 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-18T00:08:02+00:00Added an answer on June 18, 2026 at 12:08 am

    You should use a while loop :

    line = lowerBound
    while line < lineNumber:
        ...
        if conditions:
            ...
            for lineIDX in range(line, line+6):
               ...
            line = line + 6
        else:
            line = line + 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Python but have been running a few programs locally using
So basically I am still pretty new to Python and I have a problem
I'm pretty new to Python and, in writing an app, have ended up with
Pretty new to Python and have been playing around with lists and the sort
I'm pretty new to Python and I have a situation where I have a
I'm pretty new to python, but I have lots of experience with MATLAB &
I'm pretty new to Python and am completely confused by .join() which I have
I am new to python and I have been trying to change my php
I have been trying to create a web service out some python scripts, and
I'm new to Pyparsing (and pretty new to Python). I have tried to reduce

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.