|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- class wordnet():
- class word():
- def __init__(self) -> None:
- self.word = List
- self.offset = int
- self.pos = str
- def __init__(self) -> None:
- self.word_set = self.word()
- self.hyper = self.word()
- self.hypon = self.word()
- self.partOf = self.word()
-
- def output(self):
- with open('data.json', 'a', encoding='utf-8') as d:
- print(self.__dict__)
- jsonstr = json.dumps(self.__dict__)
- d.write(jsonstr + '\n')
复制代码
我想用 self.__dict__ 序列化 wordnet 的实例,但是内部类 word 无法被序列化,输出- {'word_set': <__main__.wordnet.word object at 0x000001C3B3B09B38>, 'hyper': <__main__.wordnet.word object at 0x000001C3AFDAD7F0>, 'hypon': <__main__.wordnet.word object at 0x000001C3B4946080>, 'partOf': <__main__.wordnet.word object at 0x000001C3B49461D0>}
复制代码
应该怎么解决?
|
|