我知道在C++中将类保存为二进制文件是可能的,可以使用以下方式:
file.write(Class_variable, size_of_class, amount_of_saves, file_where_to_save)
我想在Python中使用类似的方法来更轻松地编写和阅读大量数据。
我尝试了以下方法:
def Save_Game(player, room):
address = 'Saves/player'
file = open(address, 'wb')
file.write(player)
address = 'Saves/room'
file = open(address, 'wb')
file.write(room)
房间和玩家都是类对象。但它说:
TypeError: must be convertible to a buffer, not PlayerMarty
我能做什么?