"ascii" codec can't encode characters in position 0-2: ordinal not in range(128)
<p>I am using python 2.7 and used Chinese characters in my code, so...</p>

<pre><code># coding = utf-8
</code></pre>

<p>and the problem is part of my code, as follows:</p>

<pre><code>def fileoutput():
    global percent_shown
    date = str(datetime.datetime.now()).decode('utf-8')
    with open("result.txt","a") as datafile:
        datafile.write(date+"   "+str(percent_shown.get()))
</code></pre>

<p>percent_shown is a string that includes Chinese characters</p>

<p>When I run it, I get:</p>

<p>UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)</p>

<p>How to fix it? Thanks</p>