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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:02:48+00:00 2026-06-08T08:02:48+00:00

I currently got a program in Python that reads a text file but it

  • 0

I currently got a program in Python that reads a text file but it loses its formatting while staying on memory for a couple of reasons, but it keeps as information the line and column of it. I would be interested on using this line and column information to reproduce the file as it was originally read. It is ok if the column doesn’t match in amount of spaces or tabs in comparison to the original as long it is consistent thru the new file.

One first naive solution that occurred to me was to always keep some pointer to line 1 and column 1 and spam \n and white spaces using the line and column information, but I was wondering if there is a better way to do that in Python (in fact I don’t know how to do this pointer to first line and column either).

Some method that would take as parameters a string, the line, column, and the file as four parameters in Python and would maybe be a possible solution, although I am unsure in this case what would occur if (line,column) is occupied (this would never occur in my situation so is not really a concern).

Edit: The information is stored on a complicated ‘structure’, but it suffices to say that I can extract such information as a list of strings, where each string has an associated line and column information. I would then use this ‘method’ to take each string and its column and line to add to the file on the right position.

Edit 2: The only assumption is that when getting every word from the original file they will happen on exactly the same order. That is to say, if the original file is “The cat jumped \n but did not die” then it is expected that I will be taken the strings: ‘ the’, ‘cat’, ‘jumped’, ‘and’, ‘didn’t’, ‘die’ and its associated line and columns. In that case, ‘but’, ‘did’, ‘not’ and ‘die’ will have line 2 instead of 1 and all words their associated columns (which may or may not overlap since its a different line).

Thank you.

  • 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-08T08:02:50+00:00Added an answer on June 8, 2026 at 8:02 am

    You would need to order the lines in memory based on row number (y). Then for i in range (1..N), with N = number of rows per page in your original file, you would:

    - if there are rows with that y:
        - sort all rows with that y in that page using their x
        - start with j = 0, and for each text chunk:
           - write (x - j) spaces
           - write the chunk
           - set j equal to x plus the length of the chunk
    - output a carriage return and continue
    

    This would rebuild an acceptable version of the text. A slight modification with modulo 8 could even allow you to replace some of those x-j spaces with tabs.

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

Sidebar

Related Questions

I've currently got a spreadsheet type program that keeps its data in an ArrayList
I'm currently writing a program that needs to compare each file in an ArrayList
Currently I'm working on a small program that reads large files and sorts them.
So, I've got a multithreaded python program, which is currently suffering from deadlock. I
I'm currently preparing a major Program-Update and ran into following problem: I've got a
I've currently got a C# application that responds to HTTP requests. The body of
I've currently got a ruby on rails app hosted on Heroku that I'm monitoring
I've currently got a Bash command being executed (via Python's subprocess.Popen ) which is
I've currently got a query that selects metrics data from two tables whilst getting
I'm currently trying to write a voicechat program in python. All tips/trick is welcome

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.