My code looks like this:
def storescores():
hs = open(\"hst.txt\",\"a\")
hs.write(name)
hs.close()
so if I run it and enter \"Ry
There is also one fact that you have to consider. You should first check if your file is empty before adding anything to it. Because if your file is empty then I don't think you would like to add a blank new line in the beginning of the file. This code
os.path.getsize() to catch any exceptions.Code:
import os
def storescores():
hs = open("hst.txt","a")
if(os.path.getsize("hst.txt") > 0):
hs.write("\n"+name)
else:
hs.write(name)
hs.close()