title: Is adding attributes dynamically frowned upon in Python?
body: <p>In Python, you can assign an arbitrary attribute <strong>from outside the defining class</strong>:</p>
  
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User)  
      name = models.CharField(max_length=140)
  
  p = Profile()
  p.age = 42
  </code></pre>
  
  <p>The underlying mechanism here is <code>__dict__</code> attribute that maintains a dictionary of all attributes.</p>
  
  <p>We were all told <a href="https://stackoverflow.com/questions/99688/private-vs-public-members-in-practice-how-important-is-encapsulation">not to expose our inner workings to the client code</a>, but attaching <em>new</em> data doesn't have to do with encapsulation at all, right? Is this idiom common for Python code?</p>
  
  <hr>
  
  <h2>Just What I Mean…</h2>
  
  <p>Each <code>Tweet</code> has standard fields, like <code>id</code>, <code>text</code>, <code>owner</code>.<br>
  When returning tweet list for a user, you want to display if a tweet is “favorited” by this user.</p>
  
  <p>Obviously, to obtain <code>is_favorite</code> you need to query many-to-many relationship for this <code>user</code>.<br>
  Would it be OK to <strong>pre-fill <code>Tweet</code> objects with <code>is_favorite</code> corresponding to current user</strong>?</p>
  
  <p>Sure I could expose a method <code>is_favorite_for(user)</code> but I'm hitting <a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=django%20template%20language&amp;source=web&amp;cd=1&amp;ved=0CCAQFjAA&amp;url=https://docs.djangoproject.com/en/dev/topics/templates/&amp;ei=9dqqTsO8H-WJ4gT0yvz9Dg&amp;usg=AFQjCNFjUjAirZFu4vUQCUTRlyOvpDCOGg&amp;sig2=qbQhJjNibySNGXMCnd_s6Q" rel="noreferrer">Django template language</a> limitations that doesn't allow to call methods with arguments from inside the template. Also, I believe <strong>a template should not be calling methods at all</strong>.</p>
  
  <hr>
  
  <p>I know this will <em>work</em> fine, but I wonder if doing something like that in an open source project would get other developers to look on me with contempt.</p>
  
  <blockquote>
    <p>Sidenote:  </p>
    
    <p>I come from C#/.NET background where dynamic types were introduced very recently and aren't adapted widely except for some niche areas (interoperability, IoC frameworks, REST client frameworks, etc).</p>
  </blockquote>