擅长:python、mysql、java
<p>您可以使用<code>collections.abc.Mapping</code></p>
<pre class="lang-py prettyprint-override"><code>from collections.abc import Mapping
class M(Mapping):
def __iter__(self):
return iter(self.to_dict())
def __getitem__(self, item):
return self.to_dict()[item]
def __len__(self):
return len(self.to_dict())
</code></pre>