title: How can I return a default value for an attribute?
body: <p>I have an object <code>myobject</code>, which might return <code>None</code>. If it returns <code>None</code>, it won't return an attribute <code>id</code>:</p>
  
  <pre><code>a = myobject.id
  </code></pre>
  
  <p>So when myobject is <code>None</code>, the stament above results in a <code>AttributeError</code>:</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'id'
  </code></pre>
  
  <p>If <code>myobject</code> is None, then I want <code>a</code> to be equal to <code>None</code>. How do I avoid this exception in one line statement, such as:</p>
  
  <pre><code>a = default(myobject.id, None)
  </code></pre>