📅  最后修改于: 2022-03-11 14:46:37.803000             🧑  作者: Mango
class MyObject():
def __init__(self):
self.a = 1
self.b = 2
self.c = 3
def __iter__(self):
yield 'a', self.a
yield 'b', self.b
yield 'c', self.c
dict(MyObject())
>>>
{
'a': 1,
'b': 2,
'c': 3
}