相关疑难解决方法(0)

Python类的__dict __.__ dict__属性是什么?

>>> class A(object): pass
... 
>>> A.__dict__
<dictproxy object at 0x173ef30>
>>> A.__dict__.__dict__
Traceback (most recent call last):
  File "<string>", line 1, in <fragment>
AttributeError: 'dictproxy' object has no attribute '__dict__'
>>> A.__dict__.copy()
{'__dict__': <attribute '__dict__' of 'A' objects> ... }
>>> A.__dict__['__dict__']
<attribute '__dict__' of 'A' objects> # What is this object?
Run Code Online (Sandbox Code Playgroud)

如果我这样做A.something = 10,这就进入了A.__dict__.什么是这个<attribute '__dict__' of 'A' objects>发现A.__dict__.__dict__,当它包含的东西吗?

python metaprogramming class magic-methods

81
推荐指数
4
解决办法
8万
查看次数

标签 统计

class ×1

magic-methods ×1

metaprogramming ×1

python ×1