擅长:python、mysql、java
<p>在过去,我经常遇到特殊字符的问题,我都是在读取时解码为Unicode,然后在写回文件时编码为utf-8。在</p>
<p>我希望这对你也有用。在</p>
<p>对于我的解决方案,我一直使用我在这个演示文稿中找到的东西
<a href="http://farmdev.com/talks/unicode/" rel="nofollow noreferrer">http://farmdev.com/talks/unicode/</a></p>
<p>所以我会用这个:</p>
<pre><code>def to_unicode_or_bust(obj, encoding='utf-8'):
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
</code></pre>
<p>那么在你的代码上:</p>
^{pr2}$
<p>然后在写的时候把编码设置回utf-8。在</p>
<pre><code>output_zip.writestr(entry, contents.encode('utf-8'))
</code></pre>
<p>我没有重复你的问题,所以这只是一个建议。希望有用</p>