Share your repls and programming experiences

← Back to all posts
turn an object into a text file (serialization with basic data types)

serialization is turning an object into text so it can be stored or shared easier (think game save codes or some objects being sent over networks)

this is some serialization I made that can turn any object with basic data types (no dictionaries or arrays or anything of the sort) into a text file and back. The file has all of the actual code, and has the implementation. It preserves class names and variables. It does not preserve functions, but you can put an object with a function into the deserializer and the deserializer will overwrite the variables and keep the function. You could use this to make save files for games or whatever else idk.

Note: this also does preserve the types of the variables that you use. Also, I have not tested this with arrays or dicts but I know it will not work with those

Feel free to fork for yourself, but please give credit if you reuse this code