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 84643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:57:49+00:00 2026-05-10T21:57:49+00:00

I have a file and I don’t know how big it’s going to be

  • 0

I have a file and I don’t know how big it’s going to be (it could be quite large, but the size will vary greatly). I want to search the last 10 lines or so to see if any of them match a string. I need to do this as quickly and efficiently as possible and was wondering if there’s anything better than:

s = 'foo' last_bit = fileObj.readlines()[-10:] for line in last_bit:     if line == s:         print 'FOUND' 
  • 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. 2026-05-10T21:57:49+00:00Added an answer on May 10, 2026 at 9:57 pm
    # Tail from __future__ import with_statement  find_str = 'FIREFOX'                    # String to find fname = 'g:/autoIt/ActiveWin.log_2'     # File to check  with open(fname, 'r') as f:     f.seek (0, 2)           # Seek @ EOF     fsize = f.tell()        # Get Size     f.seek (max (fsize-1024, 0), 0) # Set pos @ last n chars     lines = f.readlines()       # Read to end  lines = lines[-10:]    # Get last 10 lines  # This returns True if any line is exactly find_str + '\n' print find_str + '\n' in lines  # If you're searching for a substring for line in lines:     if find_str in line:         print True         break 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flash element (I know, but please don't) with a settings.xml file.
I have a sqlite file but I don't know what tables there are in
I don't have .bashrc file, I want to create one but how? And what
Guys have a problem don't know why this is not working, i have file
I have a video file I don't know what format it is. Is there
I don't know what I did... At the moment, I only have the File
I have 10 processes running, each writing to the same file. I don't want
Textmate does not source my .profile file. I don't have a custom bash_init.rb, nor
I have a binary file which was created by a VBA file (I don't
I have the following code in an ashx file - don't ask why ;-)

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.