为内置类存储的对象的键/值对在哪里?

时间:2017-04-14 12:34:38

标签: python python-3.x dictionary

为内置类存储的键/值数据在哪里?它们不能通过“__dict__”访问,因为它们不被视为属性。

示例:

class TestNewClass(dict):
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self["item"] = c

x = TestNewClass(3, 4, 5)

print(x.a)          # 3
print(x.b)          # 4
print(x["item"])    # 5
print(x.__dict__)   # {"a": 3, "b": 4} c not considered an attribute

0 个答案:

没有答案