国产精品chinese,色综合天天综合精品网国产在线,成午夜免费视频在线观看,清纯女学生被强行糟蹋小说

    <td id="ojr13"><tr id="ojr13"><label id="ojr13"></label></tr></td>
        • <source id="ojr13"></source>
            <td id="ojr13"><ins id="ojr13"><label id="ojr13"></label></ins></td>

            Article / 文章中心

            Python編程:json序列化python對象

            發(fā)布時(shí)間:2021-11-23 點(diǎn)擊數(shù):632

            相關(guān): Python編程:json模塊和pickle模塊

            # -*- coding: utf-8 -*-  # @File    : json_demo.py # @Date    : 2018-06-04 # @Author  : Peng Shiyu  # 定制序列化或反序列化的規(guī)則 import json  class Student(object):  def __init__(self, name, age):  self.name = name  self.age = age   if __name__ == '__main__':  s = Student("Tom", 23)   # 序列化  ret = json.dumps(s, default=lambda obj: obj.__dict__)  print(ret)  # {"name": "Tom", "age": 23}   # 反序列化  def obj2student(d):  return Student(d["name"], d["age"])   s2 = json.loads(ret, object_hook=obj2student)  print(s2)  # <__main__.Student object at 0x101c7e518>