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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:42:17+00:00 2026-06-13T16:42:17+00:00

How can I compile a string from selected rows of a file, run some

  • 0

How can I compile a string from selected rows of a file, run some operations on the string and then split that string back to the original rows into that same file?

I only need certain rows of the file. I cannot do the operations to the other parts of the file. I have made a class that separates these rows from the file and runs the operations on these rows, but I’m thinking this would be even faster to run these operations on a single string containing parts of the file that can be used in these operations…

Or, if I can run these operations on a whole dictionary, that would help too. The operations are string replacements and RegEx replacements.

I am using python 3.3


Edit:
I’m going to explain this in greater detail here since my original post was so vague (thank you Paolo for pointing that out).

For instance, if I would like to fix a SubRipper (.srt-file), which is a common subtitle file, I would take something like this as an input (this is from an actual srt-file):

Here you can find correct example, submitting the file contents here messes newlines:
http://pastebin.com/ZdWUpNZ2

…And then I would only fix those rows which have the actual subtitle lines, not those ordering number rows or those hide/show rows of the subtitle file. So my compiled string might be:

“They’re up on that ridge.|They got us pinned down.”

Then I would run operations on that string. Then I would have to save those rows back to the file. How can I get those subtitle rows back into my original file after they are fixed? I could split my compiled and fixed string using “|” as a row delimiter and put them back to the original file, but how can I be certain what row goes where?

  • 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-13T16:42:19+00:00Added an answer on June 13, 2026 at 4:42 pm

    You can use pysrt to edit SubRip files:

    from pysrt import SubRipFile
    
    subs = SubRipFile.open('some/file.srt')
    
    for sub in subs:
        # do something with sub.text
        pass
    
    # save changes to a new file
    subs.save('other/path.srt', encoding='utf-8')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I compile and run a python file (*.py extension)?
I have a simple C++ program that I can compile (g++ from command line)
How can I compile java code from an arbitrary string (in memory) in Java
I learned that Xcode can compile c code, that means can we write whole
I can't compile the last line for the following code: typedef boost::variant<std::vector<int8_t>, std::vector<std::string>> Container;
I can compile this JNA example code (from step 2 of https://github.com/twall/jna/#getting_started ): package
I want a List<string> containing all the 'selected' series codes from this DataGridView: I
Trivial, but I can't seem to print a jQuery SVG polygon from a string
I got this compile time string comparison from another thread using constexpr and C++11
How can I run a ruby piece of code from a buffer, without actually

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.