How to extract information from text file in Python?

Recovering a corrupted text file?

  • I'm a writer, and regularly use notepad and .txt files to quickly jot down inspiration when it comes. As you might imagine, this results in a large quantity of irreplaceable information being stored in these files. Just now, a note file for a project I'm currently working on stopped opening. If I tried to open it in notepad, the program would stop responding and indicate it couldn't access the file after some time, suggesting it might be trying to access a file on media I'd recently disconnected. I tried accessing the file's properties, and despite a long delay, the window did eventually open. I noticed nothing unusual when it did. Acting on advice, I attempted to both copy the file to external media and open it with Open Office. The copy failed; after I told Windows to copy the file, the dialog got stuck in the 'discovering files' segment and never proceeded. I cancelled the process eventually. Opening in Open Office failed as well; the 'importing' bar made it to about half-way, where Open Office crashed entirely. I recently defragged my hard drive, and that's the only possible perpetrator I can think of. This is a .txt file; there's no fancy scripting or formatting, and I was wondering if it's possible to extract the raw text from the file through some means?

  • Answer:

    You could try right clicking on the file and if "Previous Versions" is one of the options, click on that and you should be presented with several previous versions that you can open and re-save. Suggestions to open files from removable devices is not a good one as file corruption can be the result. What usually is the cause is the temporary file that is created when you open the file is placed in temp directory on the hard drive and when the file is written (saved) the possibility of the file not being completely saved exists especially if the media has been removed right after saving. The notification to safely remove hardware is not always given.

Ken Atkinson at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

It sounds to me like the End-of-file Marker (EOF) is missing, or has been moved closer to the beginning of the Text file. This EOF thing is critical under windows. So is the files over-all size. If memory serves, that limit is around 64 KB, in Windows, which makes Text files your worst choice for tidbits, etc. Have you tried to open the file using a Linux LIVE CD? Linux goes beyond 64 KB. If that doesn't work, in future, try the free and amazing EverNote App INSTEAD, from:

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.