You can use pickle to serialize Python data. This has nothing to do with pygame.
So, if your game state is completely saved in the object foo, to save it to the "savegame" file (first import pickle):
with open("savegame", "wb") as f:
pickle.dump(foo, f)
For loading:
with open("savegame", "rb") as f:
foo = pickle.load(f)
The state of the game is all the necessary information necessary to restore the game, that is, the state of the game world, as well as any state of the user interface, etc. If your game state spreads over several objects without a single object that makes them up, you can simply sort the list with all the necessary objects.
Antti source
share