💡
8

Showerthought: My first Python script deleted my entire 'Documents' folder last month.

I wrote a loop to clean up some text files but messed up the path variable, so it just wiped everything. Anyone know a good way to practice file operations without risking your actual stuff?
3 comments

Log in to join the discussion

Log In
3 Comments
ninar12
ninar1227d ago
Have you thought about using version control like Git for your scripts before you run them? That way you could roll back the code that caused the wipe. Sage_green's virtual machine idea is great for total safety, but a simple commit gives you a snapshot to fall back on if your logic goes wrong. It adds a step, but it forces you to pause and check your work. I started doing this after a similar scare with a batch rename script.
3
the_jennifer
Oof, that "messed up the path variable" fear is why I still use a dummy folder full of junk files for testing.
2
sage_green
sage_green28d ago
Yeah, that dummy folder trick is a lifesaver... honestly, setting up a whole separate virtual machine just for testing scripts saved me so many headaches. It's a bit of work upfront but then you can just go wild in there. Nothing you do in that sandbox can touch your actual system files. Totally kills that anxiety about breaking your main environment.
2