Wrapping a Python Object
<p>I'd like to serialize Python objects to and from the plist format (this can be done with plistlib). My idea was to write a class PlistObject which wraps other objects:</p>

<pre><code>def __init__(self, anObject):
     self.theObject = anObject
</code></pre>

<p>and provides a "write" method: </p>

<pre><code>def write(self, pathOrFile):
    plistlib.writeToPlist(self.theObject.__dict__, pathOrFile)
</code></pre>

<p>Now it would be nice if the PlistObject behaved just like wrapped object itself, meaning that all attributes and methods are somehow "forwarded" to the wrapped object. I realize that the methods <code>__getattr__</code> and <code>__setattr__</code> can be used for complex attribute operations:</p>

<pre><code>    def __getattr__(self, name):
         return self.theObject.__getattr__(name)
</code></pre>

<p>But then of course I run into the problem that the constructor now produces an infinite recursion, since also <code>self.theObject = anObject</code> tries to access the wrapped object.</p>

<p>How can I avoid this? If the whole idea seems like a bad one, tell me too.</p>
