I've found a couple of others asking for help with this, but not specifically what I'm trying to do. I have a dictionary full of various formats (int, str, bool, etc) and I'm trying to save it so I can load it at a later time. Here is a basic version of the code without all the extra trappings that are irrelevant for this.
petStats = { 'name':"", 'int':1, 'bool':False }def petSave(pet):with open(pet['name']+".txt", "w+") as file:for k,v in pet.items():file.write(str(k) + ':' + str(v) + "\n")def digimonLoad(petName):dStat = {}with open(petName+".txt", "r") as file:for line in file:(key, val) = line.split(":")dStat[str(key)] = valprint(petName,"found. Loading",petName+".")return dStat
In short I'm just brute forcing it by saving a text file with a Key:Value on each line, then split them all back up on load. Unfortunately this turns all of my int and bool into strings. Is there a file format I could use to save a dictionary to (I don't need to be able to read it, but the conveniance would be nice) that I could easily load back in?
This works for a basic dictionary but if I start adding things like arrays this is going to get out of hand as it is.