I've searched around and have not been able to find a solution to my specific problem. What i am trying to do is take a text file, where I have each line of the file hold a variable.
in the text file line by line i have
health == 1099239
gold == 123
otherVar == 'Town'
The problem with this is I cant get them separated into different variables instead of just one variable with all the information in it.
Currently i have this as the test for saving into the file
SaveFileName = input('What would you like to name your save: ')
f = open(SaveFileName + '.txt','w+')
health = input('Health: ')
gold = input('Gold: ')
otherVar = input('Other: ')
otherVar = ("'" + otherVar + "'")
f.write('health == ' + health +'\ngold == ' + gold + '\notherVar == ' + otherVar)
print('done')
f.close()
print('closed')
My problem is not with saving, as this seems to work exactly as intended.
Here's the loading
SaveFileName = input('Save name to load: ')
global health
global gold
global otherVar
health = 100
gold = 1000
otherVar = 'null'
def pause():
pause = input('Press enter to continue. ')
F = open(SaveFileName + '.txt')
for line in F:
eval(F.readline())
print(health)
pause()
print(gold)
pause()
print(otherVar)
pause()
When i run the Loading file it allows me to input the save file name, then returns this on loading
Traceback (most recent call last):
File "C:/Users/Harper/Dropbox/Python programming/Test area/Load file test.py", line 12, in <module>
eval(F.readline())
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing