在 Pycharm 中运行以下程序:
#! /usr/bin/python
# -*- coding: utf8 -*-
print "running test..."
print u"测试"
w = raw_input(u"输入:".encode("mbcs"))
print u"%s" % (w)
a = u"中文"
print u"Show As: %s" % (a)
在控制台中输出始终存在乱码:
running test...
����
���룺aaa
aaa
Show As: ����
但是,该程序在 Windows 的命令行中运行正常:
running test...
测试
输入:aaa
aaa
Show As: 中文
这里 PyCharm 的 “IDE Encoding” 和 “Project Encoding” 无论设置为 UTF-8 还是 GBK 对乱码均没有显著效果。但是,如果直接
print "测试"
却可以正常输出。
请教一下大家,这里该怎么设置才能保证各平台下中文显示均正常?(注:chcp 为 936)
-- coding: utf8 -
这个要写在第一行
在setting里面把file encoding改成utf-8就好。