I have code that converts an integer into a string to write it into a file, but the code to convert it back into an integer so I can put it through simple equations doesn’t work.
my code: writing:
saveposx = open("sevedposx.txt", "w")
saveposy = open("sevedposy.txt", "w")
saveposx.write(str(x))
saveposy.write(str(y))
where x = 32
and y = 32
as well
reading:
readposx = open("sevedposx.txt", "r")
readposy = open("sevedposy.txt", "r")
posx = readposx.read(50)
posy = readposy.read(50)
actposx = int(posx)
actposy = int(posy)
actpos = ((actposx - 2), (actposy - 2))
x
and y
are defined outside a loop as to allow rewriting of x
and y
.
My code gives me this error:
File "name_yet_to_come.py", line 399, in <module>
actposx = int(posx)
ValueError: invalid literal for int() with base 10: ''
Thanks