I made it possible for a computer program to kill itself

well i guess it not really killing it is is just deleting all the code inside it and replacing it

what i have done is use this line to delete the code open("main.py", "w").write("I replace with a bit of new code") but before i delete all the code i save that code in a txt file with open("backup", "w").write(open("main.py").read()) and if the user want to revive the program or restore the code it can grab the all the stuff from the txt file and put it in main.py

So it will give the illusion of the program dying

How to actually kill a computer program with no code

First of all why do you wanna kill a computer program what did a computer program ever do to you

But since you asked

if you really want to kill a computer program just hit delete repl

Link to my repl
1 Like

This is a good example of Python file manipulation. Well done @TheOtherGuy but I hope you don’t accidentally lose any programs!

yeah that would suck
but i only spent like 5 minutes on it
thanks @IanAtReplit

If you want it to quit you could use this :

1 Like

Quit stops the program, what TheOtherGuy is doing is deleting the file that runs the program, but then recreating it within the same script…

1 Like

But this won’t stop the program, I think using quit() for killing the program is better. This would be a great solution for when you want to kill a task completely and start a new task instead or to display something custom after program is killed👍

1 Like

Ohh, nice @TheOtherGuy!

1 Like

Nice thanks @MattDESTROYER and @Hugo and @Pro0grammer