我無法理解的對象實例和對象繼承實例之間的區別:對象及其繼承
1. __dict__
,__module__
,__weakref__
- 在這種性質的?
>>> dir(object)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
>>> dir(type('tt',(object,),{}))
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
2.我不能將propetry設置爲對象實例。
>>> b= object()
>>> b.f = 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'f'
>>> b = type('tt',(object,),{})()
>>> b.f = 4
這種差異是否來自內建式生成器?爲什麼?