Oct-12-2023, 04:01 AM
So to expand on this question. My fix worked on my first class but the second class threw an error saying (object not serializable).
So on my second class I went back to this:
So to try and import them back in I ran the following:
If you look at the screenshot below its putting ticks around all the variables of the class. Is this because when I use:
I've done a lot of googling and from what I gathered exporting the object out as JSON can be easy but bringing it back in is where things can get complicated and might not be as easy as a single line of code.
So on my second class I went back to this:
warMapStaticDump = json.dumps(warMapStatic, default=lambda x: x.__dict__, indent=4)And here is the class in question:
class fxWarMapStatic: def __init__(self, mapName): self.mapName = mapName self.regionId = None self.eTag = None self.scorchedVictoryTowns = None self.lastUpdated = None self.version = None self.mapTextItems = []Now I can have multiple of these objects. Each one being unique and read in from a separate JSON file.
So to try and import them back in I ran the following:
with open(warMapStaticDataDump, 'r') as j: fxWarConquest.fxWarMapStatics.append(json.loads(j.read()))This appears to be working its not and I think my ignorance of Python is where I don't understand what its doing.
If you look at the screenshot below its putting ticks around all the variables of the class. Is this because when I use:
default=lambda x: x.__dict__Its converting my object to dictionaries and when I bring it back in it places everything correctly but as dictionary objects not variables? Once again, I might be butchering all these terms.
I've done a lot of googling and from what I gathered exporting the object out as JSON can be easy but bringing it back in is where things can get complicated and might not be as easy as a single line of code.
![[Image: GP0IJBA.png]](https://i.imgur.com/GP0IJBA.png)