短答案:运用Python3
长答案:
# -*- coding: utf8 -*-
# 尽早将统统转到UTF-8
unicode_str = unicode('中文', encoding='utf-8')
# 打印或许写入前用UTF-8编码
print unicode_str.encode('utf-8')
# 用codecs.open替代open
import codecs
codecs.open('filename', encoding='utf8')
短答案:运用Python3
长答案:
# -*- coding: utf8 -*-
# 尽早将统统转到UTF-8
unicode_str = unicode('中文', encoding='utf-8')
# 打印或许写入前用UTF-8编码
print unicode_str.encode('utf-8')
# 用codecs.open替代open
import codecs
codecs.open('filename', encoding='utf8')