I have this code as follow:
print("hello")
print("hello")
print("hello")
print("hello")
x = open("main.py", "a")
x.write("hello")
My objective for this code is for it to print "hello" four times (of which it does), and then after that I want the file to be overwritten so that it contains the word "hello". Ie. I want the python code to be replaced with the word "hello" after the program is finished. However, instead what happens is that it prints "hello" four times, and then the python file just clears itself, is blank, instead of having the word "hello".
I know you can write on other files, but it seems that when writing on the file of itself, things are different. How do I fix this?