本文整理汇总了Python中object.Object.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Object.serialize方法的具体用法?Python Object.serialize怎么用?Python Object.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类object.Object
的用法示例。
在下文中一共展示了Object.serialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import serialize [as 别名]
def serialize(self):
"""
Convert Item to a string, suitable for saving to a file.
"""
# Need to trim off the trailing bracket from the Object serialization.
obj = Object.serialize(self)[:-1]
if self.use_function is None:
use_function = None
else:
use_function = self.use_function.__name__
item = "'use_function':{0},}}".format(repr(use_function))
return obj + item
示例2: serialize
# 需要导入模块: from object import Object [as 别名]
# 或者: from object.Object import serialize [as 别名]
def serialize(self):
"""
Convert Monster to a string, suitable for saving to a file.
"""
# Need to trim off the trailing bracket from the Object serialization.
obj = Object.serialize(self)[:-1]
if self.ai is None:
ai = None
else:
ai = repr(self.ai.__class__.__name__)
inventory = repr([item.oid for item in self.inventory])
mon = ("'hp':{0},'max_hp':{1},'mp':{2},'max_mp':{3},'ai':{4},"
"'death':{5},'inventory':{6}}}".format(
repr(self.hp), repr(self.max_hp), repr(self.mp),
repr(self.max_mp), ai, repr(self.death.__name__), inventory))
return obj + mon