I was working on a saving mechanic for a game I am making, and kept getting the error _pickle.UnpicklingError: could not find MARK
. I checked the data it was producing and noticed that it was creating a new line near the end of the data, and because I am reading line by line that broke everything. I tried the solution from this answer. This solved my problem temporarily, but now the error has returned, and changing the variable names isn't helping.
This is my code for saving:
with open("pastgames", "ab") as file:
data = []
tempdata = []
#for all the data write it to a list then pickle that list and put it in a file
for i in rownums:
tempdata.append(i.nums)
data.append(tempdata)
tempdata = []
for x in dots:
tempdata.append(x.color)
data.append(tempdata)
data.append(combo)
data.append((time.year, time.month, time.day, time.hour, time.minute))
dumpdata = pickle.dumps(data)
file.write(dumpdata + b"\n")
And this is my code for reading:
with open("pastgames", "rb") as file:
content = file.readlines()
data = pickle.loads(content[dataind])
More code can be found at this GitHub repo. Apologies if my code is hard to read, help with that would be much appreciated.
Thank you in advance
**Update: ** So I found the issue, it doesn't work at 10 o'clock. The way I am formatting the data creates a 0A
byte, which it mistakes for a newline character. I saw some comments about just using pickle.load(file)
but that just ended up returning the first item in the data file. More help on that would be much appreciated. Thanks!