Adding to the dir() of instance
<p>I have a class (named "A") with some instance variables. I want to add the dir() of this variables to the dir() of instances of class A.</p>

<p>For example:</p>

<pre><code>class A(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
class X(object):
    def f_x(self):
        pass
class Y(object):
    def f_y(self):
        pass

x = X(); y = Y()
a = A(x,y)
</code></pre>

<p>I want f_x and f_y to appear in</p>

<pre><code>dir(a)
</code></pre>

<p>Is there a better way, or a more 'correct' one, than just iterating X.<strong>dict</strong> and Y.<strong>dict</strong> and for each element, use something like:</p>

<pre><code>setattr(A, str(element), element)
</code></pre>

<p>Thanks.</p>
