0

Weeks ago, I used Python to write a txt file (xyz.txt) onto disk, then manually added some content to the file (using a text editor). Today I accidently rerun the code block so all contents I added are missing. Is it possible to recover the file?

The code I use is as follows:

with open("xyz.txt", "w") as file:
    for line in data_list:
        file.write(f"{line}\n")

No timemachine backup. No icloud backup. I tried DiskDrill but it can not find the previous version that contained my manually added contents.

I am working on a Macbook pro laptop.

Eric Z
  • 1
  • 1
    `strings`, like [here](https://superuser.com/a/1709088/432690), but starting from the block device instead of an image. Until you find what you seek, you want to stop writing to the device. And you certainly don't want `strings` to write to the device, because it may find its own output and "loop". Then `grep -A … -B …` or `grep -n …`, using a string you remember was in the lost content. – Kamil Maciorowski Nov 19 '22 at 08:07
  • They close ANY post about data recovery and refer to that rabbit hole wiki. Better listen to @KamilMaciorowski, but know that even when the text survived it may be overwritten at any time. – Joep van Steen Nov 19 '22 at 10:06
  • 1
    @JoepvanSteen You can discuss this with "them" on [meta]. – gronostaj Nov 19 '22 at 10:40
  • @gronostaj; Okay thank you. So I can just open new question there and discuss in general or this ^ question specifically? – Joep van Steen Nov 19 '22 at 10:49
  • @JoepvanSteen Yes. Regardless what happens to this question, I think a good thing to do is to add a solution involving `strings` as an answer to the other question, so that one is complete and can still serve as canonical. Maybe I will do it in few hours. – Kamil Maciorowski Nov 19 '22 at 12:27
  • 1
    @JoepvanSteen The Meta is a site _about_ Super User. You can discuss individual questions, general policies, request explanation why a question was closed and so on. It uses the same Q&A engine as the main site, but it's more open for discussion in the comments. – gronostaj Nov 19 '22 at 14:33

0 Answers0