Why python IDLE and Console produce different results
<p>I write a simple Python script to translate Chinese Punctuation to English.</p>

<pre><code>import codecs, sys

def trcn():
    tr = lambda x: x.translate(str.maketrans("""，。！？；：、（）【】『』「」﹁﹂“”‘’《》～￥…—×""", """,.!?;:,()[][][][]""''&lt;&gt;~$^-*"""))
    out = codecs.getwriter('utf-8')(sys.stdout)
    for line in sys.stdin:
        out.write(tr(line))

if __name__ == '__main__':
    if not len(sys.argv) == 1:
        print("usage:\n\t{0} STDIN STDOUT".format(sys.argv[0]))
        sys.exit(-1)
    trcn()
    sys.exit(0)
</code></pre>

<p>But something is wrong with <strong>UNICODE</strong>.
I cannot get it passed. Error msg:</p>

<pre><code>Traceback (most recent call last):
  File "trcn.py", line 13, in &lt;module&gt;
    trcn()
  File "trcn.py", line 7, in trcn
    out.write(tr(line))
  File "C:\Python31\Lib\codecs.py", line 356, in write
    self.stream.write(data)
TypeError: must be str, not bytes
</code></pre>

<p>After then, I test the <strong>out.write()</strong> in IDLE and Console.
They produced different results.
I don't know why.</p>

<p><strong>In IDLE</strong></p>

<pre><code>Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
&gt;&gt;&gt; import sys,codecs
&gt;&gt;&gt; out = codecs.getwriter('utf-8')(sys.stdout)
&gt;&gt;&gt; out.write('hello')
hello
&gt;&gt;&gt;
</code></pre>

<p><strong>In Console</strong></p>

<pre><code>Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import sys,codecs
&gt;&gt;&gt; out = codecs.getwriter('utf-8')(sys.stdout)
&gt;&gt;&gt; out.write('hello')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Python31\Lib\codecs.py", line 356, in write
    self.stream.write(data)
TypeError: must be str, not bytes
&gt;&gt;&gt;
</code></pre>

<hr>

<p><strong>Platform: Windows XP EN</strong></p>
