class UnicodeStreamFilter:
def __init__(self, target):
self.target = target
self.encoding = 'utf-8'
self.errors = 'replace'
self.encode_to = self.target.encoding
def write(self, s):
if type(s) == str:
s = s.decode("utf-8")
s = s.encode(self.encode_to, self.errors).decode(self.encode_to)
self.target.write(s) if sys.stdout.encoding == 'cp936':
sys.stdout = UnicodeStreamFilter(sys.stdout)
相关文章
- windows下Emacs中文乱码解决办法[2013-03-07更新]
- Windows下CLion中文乱码最有效的解决方式
- windows下使用gvim不支持python3.6问题解决
- [python] virtualenv下解决matplotlib中文乱码
- Windows下NetBeans中文乱码解决办法
- Python基础知识--windows环境下python和pip命令找不到如何解决
- (亲测解决)Windows下Vim中无法输入中文
- Windows cmd下运行python脚本报错“ImportError: No Module named ...”的解决方法
- Windows环境下Python 安装库 is not a supported wheel on this platform解决办法【转】
- 解决Python的print中文在windows命令行乱码问题