title: Default encoding for python for stderr?
body: <p>I've got a noisy python script that I want to silence by directing its stderr output to /dev/null (using bash BTW).</p>
  
  <p>Like so:</p>
  
  <pre><code>python -u parse.py  1&gt; /tmp/output3.txt 2&gt; /dev/null
  </code></pre>
  
  <p>but it quickly exits prematurely. Hmm. I can't see the traceback because of course that goes out with stderr. It runs noisily and normally if I don't direct stderr somewhere.</p>
  
  <p>So let's try redirecting it to a file somewhere rather than /dev/null, and take a look at what it's outputting:</p>
  
  <pre><code>python -u parse.py  1&gt; /tmp/output3.txt 2&gt; /tmp/foo || tail /tmp/foo
  
  Traceback (most recent call last):
    File "parse.py", line 79, in &lt;module&gt;
      parseit('pages-articles.xml')
    File "parse.py", line 33, in parseit
      print &gt;&gt;sys.stderr, "bad page title", page_title
  UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
  </code></pre>
  
  <p>So, the stderr that's being generated contains utf8, and for some reason python refuses to print non-ascii when it's being redirected, even though it's being directed to /dev/null (though of course python doesn't know that).</p>
  
  <p>How can I silence the stderr of a python script even though it contains utf8? Is there any way to do it without re-writing every print to stderr in this script?</p>