可能重复:
可以设置 Python 对象的任何属性
In [67]: obj = object()
In [68]: obj.x = 42
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/user/<ipython-input-68-0203a27904ca> in <module>()
----> 1 obj.x = 42
AttributeError: 'object' object has no attribute 'x'
In [69]: class myc(object):
....: pass
....:
In [70]: my = myc()
In [71]: my.x = 42
好像有违和感。object
如何在不允许添加新属性的情况下使我的类类似于?