First page Back Continue Last page Overview Graphics

Avoiding dynamically created attributes

The attributes of objects are stored in a dictionary „__dict__“.

Like any other dictionary, you can add elements after they have been defined.

>>> class A(object): ... pass ...

>>> a = A() >>> a.x = 66 >>> a.y = "dynamically created attribute"

The attributes of „a“ can be accessed like this:

>>> a.__dict__ {'y': 'dynamically created attribute', 'x': 66}