class Player:
def __init__(self):
self.money = 0
self.level = 0
self.xp = 0
self.xp_until_level = 20
self.taxi_car = "Cabbie"
self.busines = "Нет"
self.busines_income = 1000
self.upgrade_cost = 10000
self.car_speed = 10
self.car_level = 0
self.drives_until_new_car = 20
p = Player()
我不知道如何保存self
价值观。我制作文字游戏并保存数据是我的首要问题。
自我值是您的实例的属性。只需腌制你的实例(这里p
)并且它存储所有属性:
import pickle
class Player:
def __init__(self):
self.money = 0
self.level = 0
self.xp = 0
self.xp_until_level = 20
self.taxi_car = "Cabbie"
self.busines = "Нет"
self.busines_income = 1000
self.upgrade_cost = 10000
self.car_speed = 10
self.car_level = 0
self.drives_until_new_car = 20
p = Player()
pickled = pickle.dumps(p)
new_obj = pickle.loads(pickled)
print(new_obj.taxi_car) # Cabbie
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)