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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:36:11+00:00 2026-06-04T06:36:11+00:00

while calling readlines() on a .srt file , I got a list of characters

  • 0

while calling readlines() on a .srt file , I got a list of characters with lots of leading and trailing whitespace like below

with open(infile) as f:
    r=f.readlines()
    return r

I got this list

['\xef\xbb\xbf1\r\n', '00:00:00,000 --> 00:00:03,000\r\n', "[D. Evans] Now that you've written your first Python program,\r\n",'\r\n', '2\r\n', '00:00:03,000 --> 00:00:06,000\r\n', 'you might be wondering why we need to invent new languages like Python\r\n', '\r\n']

I have only included a few elements for brevity..How do I clean this list sothat I can remove all whitespace characters and get only the relevant elements like

 ['1','00:00:00,000 --> 00:00:03,000',"[D. Evans] Now that you've written your first Python program"...]
  • 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-04T06:36:12+00:00Added an answer on June 4, 2026 at 6:36 am

    You can strip each line. Running it as a generator could also save you some memory if you’re working on a big file.

    Also, looks like you’re working on a UTF-8 file with a BOM (which is sort of silly, or at least unnecessary) for the first several characters, so you need to open it differently.

    import codecs
    
    def strip_it_good(file):
        with codecs.open(file, "r", "utf-8-sig") as f:
            for line in f:
                yield line.strip()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Errors while calling int getopt function from http://code.google.com/p/darungrim/source/browse/trunk/ExtLib/XGetopt.cpp?r=17 `check.cpp: In function ‘int main()’:` check.cpp:14:55:
I am observing a crash while calling the CMemFile::Detach() function The exception with the
I have a problem with header & footer while calling one external html page
It seems that calling a P-Invoke while the App is not completed loaded make
While following path for wait system call, noticed that before calling do_wait_thread we get
All, I am trying to ensure that a file I have open with BufferedReader
While calling XslCompiledTransform.Transform() method I get this exception : The Writer is closed or
I am having a problem while calling overloaded C# function through jquery post method.
Why does Oracle 10 R2 not allow use of notational parameters while calling functions
I have a problem returning/processing JSON data while calling $.get() function. Here's the code:

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.