【问题标题】:Unicode strings in pydevpydev 中的 Unicode 字符串
【发布时间】:2013-08-20 09:28:24
【问题描述】:

我正在为 Eclipse 使用 pydev 插件,并且在尝试包含 unicode 字符串时遇到了问题。据我所知,这不是命令行上 pydev 和 python 之间 unicode 兼容性的常见问题。

如果我使用如下的 unicode 字符串:

INFINITY_STRING = u"\u5555"

pydev 用错误标记它:

Multiple markers at this line

- occurrence
- Undefined variable: u
- Encountered "\"\\u5555\"" at line 54, column 13. Was expecting one of:     <NEWLINE>                    ...     "(" ...     "[" ...     ";" ...     "," ...     "." ...     "+" ...     "-" ...       "*" ...     "/" ...     "//" ...    
"<<" ...     ">>" ...     "%" ...     "^" ...     "|" ...     "&" ...     "=" ...     ">" ...     "<" ...     "==" ...     "<=" ...     ">=" ...     "!=" ...     "or" ...     "and" ...     "not" ...     "is" ...     "in" ...     "if" ...     
";" ...     "," ...

代码可以编译并运行,但是这个假定的错误会扰乱自动完成和重构功能。有谁知道如何防止 pydev 在出现 unicode 字符串时抛出错误?

【问题讨论】:

  • 我在 Win7、Eclipse 3.6.1、Python 2.6 和 pydev 2.7.1 上看不到任何问题。如果您指定编码(例如# -*- coding: utf-8),也许它会有所帮助?

标签: python eclipse unicode pydev


【解决方案1】:

我猜你已经配置 pydev 使用 Python 3 运行代码,但你在命令行上使用 Python 2。

Python 3.0 doesn't support the u prefix for strings 了; Python 3 中的所有字符串都已经是 Unicode。

请注意,它已使用 Python 3.3(PEP-0414docs)恢复。感谢Janne Karila 指出这一点。

【讨论】:

  • 谢谢,你完全正确,我很困惑你是否需要 python 3.3 中的“u”。
猜你喜欢
  • 1970-01-01
  • 2019-05-12
  • 2019-04-09
  • 1970-01-01
  • 2017-11-19
  • 2012-07-26
  • 1970-01-01
相关资源
最近更新 更多