I was working on my game using pygame and I tried to implement a high score mechanism. But when I run my program it just crashed and it seems it deleted itself forever. Now when I open my code there is just 0 writen in. Is there a way to get my code back and why did it delete itself? (I tried to implement high score by making a new .txt file and by storing scores into it. I wrote it all in my same game script.)
What you most likely did was open your file and override it with 0. Whenever you open files you have to consider the mode you open it in (and which file you open.). For example, opening a file with 'w' will remove all previous content in the file and fill it with whatever you write to it.
If this is what happened, then no, there's no way to get back your code (unless you've saved a copy somewhere else or are using a Version Control System like git or svn).
If you're using the editor Pycharm, then you can right-click your project and press Local history and then Show History to open saved versions. Then click revert to go back to the version where you had your code.
Deleted program by itself