mac 环境下 Python 的中文支持?

2015-11-21 22:07:58 +08:00
 inv
最近刚换了 mac ,但是在 mac 下写 Python 的时候发现这样一个问题。就算在代码首行加入#coding=utf-8 ,还是会报字符编码的错误,求解~~~
5374 次点击
所在节点    Python
11 条回复
meloncrashed
2015-11-22 00:44:38 +08:00
# -*- coding utf-8 -*-
meloncrashed
2015-11-22 00:45:24 +08:00
# -*- coding: utf-8 -*-
julyclyde
2015-11-22 10:20:40 +08:00
lz 的编码看起来是正确的。你举个最小化例子让我看看到底是咋错的
lwbjing
2015-11-22 10:48:03 +08:00
2.7.6 同 #coding=utf-8 并没有问题啊...
inv
2015-11-22 11:40:30 +08:00
@julyclyde
类似于这样:
#coding=utf-8
#中文
print "aa"
会报这样的错误:
File "/Users/inv/PycharmProjects/s_scan/test.py", line 3
SyntaxError: Non-ASCII character '\xe4' in file /Users/inv/PycharmProjects/s_scan/test.py on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
lixia625
2015-11-22 13:01:39 +08:00
快别折腾了 用 python3
TaMud
2015-11-22 14:57:13 +08:00
mac os x ->python 2.6
update!
ntyangxd
2015-11-22 17:16:12 +08:00
文件格式也要 utf8
inv
2015-11-22 19:46:59 +08:00
@TaMud 现在的 Python 版本是 2.7.10
ericls
2015-11-23 04:45:31 +08:00
你连一个例子也不给 别人怎么回答

你是在 Python 里面 print('你好世界') 还是干了什么 导致了这个错误?
julyclyde
2015-11-24 18:01:29 +08:00
@inv 我觉得不太可能。你确定 coding=utf-8 这几个字的拼写没错吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/237939

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX