title: How do I override the str function without raising a UnicodeEncodeError?
body: <p>I am puzzled that defining <code>__str__</code> for a class seems to have no effect on using the <code>str</code> function on a class instance. For example, I read in the Django documentation that:</p>
  
  <blockquote>
    <p>The <code>print</code> statement and the <code>str</code> built-in call <code>__str__()</code> to determine the human-readable representation of an object.</p>
  </blockquote>
  
  <p>But that doesn't appear to be true. Here's an example from a module where <code>text</code> is always assumed to be unicode:</p>
  
  <pre><code>import six
  
  class Test(object):
  
      def __init__(self, text):
          self._text = text
  
      def __str__(self):
          if six.PY3:
              return str(self._text)
          else:
              return unicode(self._text)
  
      def __unicode__(self):
          if six.PY3:
              return str(self._text)
          else:
              return unicode(self._text)
  </code></pre>
  
  <p>In Python 2, it gives the following behavior:</p>
  
  <pre><code>&gt;&gt;&gt; a=Test(u'café')
  &gt;&gt;&gt; print a.__str__()
  café
  &gt;&gt;&gt; print a # same error with str(a)
  ---------------------------------------------------------------------------
  UnicodeEncodeError                        Traceback (most recent call last)
  &lt;ipython-input-63-202e444820fd&gt; in &lt;module&gt;()
  ----&gt; 1 str(a)
  
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 3: ordinal not in range(128)
  </code></pre>
  
  <p>Is there a way to overload the <code>str</code> function?</p>