jeudi 30 avril 2015

Python - not write to file

I am making a save option for a text-based survival and I cannot get the save to work right. This is the error I get:

IOError: File not open for reading

f = open('saves.txt','w')
file = f.read()
file = file.split("\n")
savefile = []
for line in file:
    temp = line.split("-")
    if name == temp[0]:
        savefile.append("%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s" % (name,story,stats,place,health,accuracy,level,exp,cash,inventory,loadingSpeed,electricity,pistolUpgrade))
    else:
        savefile.append(line)
savefile = '\n'.join(savefile)
f.write(savefile) # python will convert \n to os.linesep
f.close() # you can omit in most cases as the destructor will call if

Aucun commentaire:

Enregistrer un commentaire