Elegant way of grouping attributes
<p>I want to group attributes of instances of a class, so that it would be easy to iterate through all the attributes belonging to a group. The obvious answer would be to put all these into a list or dict, but then I wouldn't be able to access them as attributes of my object, and I would prefer that.</p>

<p>Some code should make it clear what I want. Here I actually have a list and real attributes.</p>

<pre><code>class Vectors(object):

    def __init__(self, v1, v2, v3):
        self.v1 = v1
        self.v2 = v2
        self.v3 = v3
        self.rotatable = ['v2', 'v3']

    def rotate(self, angle):
        for v in self.rotable:
            new_vector = do_rotate(getattr(self, v), angle)
            setattr(self, v, new_vector)

class MoreVectors(Vectors):
    def __init__(self, v4, *args, **kwargs):
        super(MoreVectors, self).__init__(*args, **kwargs)
        self.v4 = v4
        self.rotable.append('v4')
</code></pre>

<p>Now when calling <code>rotate()</code> it know what vectors to rotate and I can add more vectors to that list dynamically. However, while this does its job, it doesn't look that elegant to me as I have to manage the list by myself.</p>

<p>Is there some simpler way to write this? I thought about storing all attributes in a dictionary, where each group is a key, and then use <code>properties()</code> to let me access all  items of the dictionary as attributes. That would be clean enough for me, but I don't know how to set properties dynamically inside a method.</p>
