How can I make a custom conversion from an object to a dict?
<p>I have a Python class that stores some fields and has some properties, like</p>

<pre><code>class A(object):
  def __init__(self, x, y):
    self.x = x
    self.y = y

  @property
  def z(self):
    return self.x+1
</code></pre>

<p>What changes do I need to make to the class so that I can do</p>

<pre><code>&gt;&gt;&gt; a = A(1,5)
&gt;&gt;&gt; dict(a)
{'y':5, 'z':2}
</code></pre>

<p>where I specify that I want to return <code>y</code> and <code>z</code>? I can't just use <code>a.__dict__</code> because it would contain <code>x</code> but not <code>z</code>. I would like to be able to specify anything that can be accessed with <code>__getattribute__</code>.</p>
