title: How to check if an attribute has default value defined in __init__
body: <p>How can I check if an attribute of an object has been set by the user or not? Currently, I have a class</p>
  
  <pre><code>class foo:
      def __init__(self):
          self.bar = 'baz'
  </code></pre>
  
  <p>Later I would like to check if the user set the value of <code>bar</code> or not, i.e. with something like</p>
  
  <pre><code>my_foo = foo()
  my_foo.bar = 'mybaz'
  </code></pre>
  
  <p>so I would like to know if the second line above has been called or not (to throw a warning if it has not). I have two solutions, but I don't like either of them:</p>
  
  <ol>
  <li><p>Check if <code>my_foo.bar</code> is equal to the default value. But it could be that the user sets <code>my_foo.bar</code> to the same value and then I don't want to throw a warning.</p></li>
  <li><p>Don't set the default value in <code>__init__</code>, but only when it is used. Then it can be checked with <code>getattr()</code> and set with <code>setattr()</code>.</p></li>
  </ol>
  
  <p>I'm sure there is an elegant pythonic way to do it that I haven't thought of.</p>