Using a class as a structure/container

david.car7 at david.car7 at
Wed Feb 6 03:59:48 CET 2008

Is it appropriate to use a class as a simple container in order to
access attributes using a series of dot operators?  Is their a more
Pythonic way of doing this?  For instance, I have a "container" class
which is never instantiated directly, but only through another class.
Access to certain attributes would be something like:


where row and v1 are instances of the container class which are
instantianted by main_class.  I know I can use dictionaries, but this
syntax is a little clearer as long as the number of dot operators is
not too lengthy.  Some code would be something like:

class container(object):
    def __init__(self):

class main_class(object):
    def __init__(self):
        self.a = container()
        settatr(self.a, 'b', container())
        settatr(self.a.b, 'x', 2)

Thanks in advance.

More information about the Python-list mailing list