pydev中的Unicode字符串

时间:2013-08-20 09:28:24

标签: python eclipse unicode pydev

我正在使用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字符串时抛出错误?

1 个答案:

答案 0 :(得分: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指出这一点。