How can I create an object and add attributes to it?

I want to create a dynamic object in Python and then add attributes to it. This didn't work:

obj = object()
obj.somefield = "somevalue"

AttributeError: 'object' object has no attribute 'somefield'


For details on why it doesn't work, see Can't set attributes on instance of "object" class.

← Назад к списку