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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:27:44+00:00 2026-06-14T17:27:44+00:00

I have log file in wich at some point I added timestam creation and

  • 0

I have log file in wich at some point I added timestam creation and now it look like this:
log.txt:

327555
327563
327570
327601
2012-11-19 22:21:37 :: 327001
2012-11-19 22:21:37 :: 327004
2012-11-19 22:21:37 :: 327007
2012-11-19 22:21:37 :: 327008

In my Python script i used to read all lines from log.txt and add it line-by-line to a set for futher usage:

log_file = open('log.txt')
set_log = set([])
for line in log_file:
    set_log.add(line.strip())
log_file.close()

But since timestam was added this solution and gives me wrong values in my set ( it includes timestam as well).

Q: How to make it more flexible, so it udersteads lines without timestams and WITH timestams and extract only proper values?

  • 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-14T17:27:45+00:00Added an answer on June 14, 2026 at 5:27 pm

    Just parse away the timestamps. ln.split()[-1] will return the last element after splitting on whitespace, which seems to be what you’re after, so

    set_log = set(ln.split()[-1] for ln in log_file)
    

    (Using a generator comprehension to replace your loop. The strip() is no longer needed as split() removes all whitespace.)

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

Sidebar

Related Questions

I have a log.txt file on the root of my application. I would like
I have a log file that looks like the following: 2010-05-12 12:23:45 Some sort
I have a log file with content like this: 2012-07-16 03:20:41,23796160897,Text,id:SAR-23796160897-c0-2-1 sub:000 dlvrd:001 submit
Lets say we have a log file (preferably a txt file) available in the
I have a log file stored in an SQLite database which I would like
I have a log file with the string ERROR on some lines. I want
I have a log file which has lines like below. 10.10.205.100 100.10.56.5 - [23/Oct/2012:15:30:01
I have a log file that has the following appender added to it :
I have a log file assume it to be any text(txt) file. I am
I have a log file in text file format. the log file looks like

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.