In python, is there a setdefault() equivalent for getting object attributes?
<p>Python's <a href="http://docs.python.org/library/stdtypes.html#dict.setdefault" rel="nofollow">setdefault</a> allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter <CODE>default</CODE>.  You then fetch whatever is at the key in the dictionary.</p>

<p>Without manipulating an object's <CODE><a href="http://docs.python.org/library/stdtypes.html#object.%5F%5Fdict%5F%5F" rel="nofollow">__dict__</a></CODE>Is there a similar function for objects? </p>

<p>e.g.<BR>
I have an object <CODE>foo</CODE> which may or may not have attribute <CODE>bar</CODE>.  How can I do something like:</p>

<pre><code>result = setdefaultattr(foo,'bar','bah')
</code></pre>
