6

Why do I need

class DummyObject(object):
    pass

in order to make

dummy = DummyObject()
dummy.foo = 42

Why isn't this legal in Python?

dummy = object()
dummy.foo = 42

Which gives the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'foo'
mhlester
  • 22,781
  • 10
  • 52
  • 75

0 Answers0