Warum können Sie dem Objekt in Python keine Attribute hinzufügen? [Duplikat

Diese Frage hat hier bereits eine Antwort:

Attribute der Objektklasse können nicht gesetzt werden 6 answers

(In Python-Shell geschrieben)

>>> o = object()
>>> o.test = 1

Traceback (most recent call last):
  File "<pyshell#45>", line 1, in <module>
    o.test = 1
AttributeError: 'object' object has no attribute 'test'
>>> class test1:
    pass

>>> t = test1()
>>> t.test

Traceback (most recent call last):
  File "<pyshell#50>", line 1, in <module>
    t.test
AttributeError: test1 instance has no attribute 'test'
>>> t.test = 1
>>> t.test
1
>>> class test2(object):
    pass

>>> t = test2()
>>> t.test = 1
>>> t.test
1
>>> 

Warum erlaubt Ihnen object nicht, Attribute hinzuzufügen?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage