【发布时间】:2011-10-01 07:58:16
【问题描述】:
所以我有一个 python 脚本,为了方便起见,我更喜欢在 python 3.2 和 2.7 上工作。
有没有办法让 unicode 文字同时适用于两者?例如
#coding: utf-8
whatever = 'שלום'
上面的代码在 python 2.x (u'') 中需要一个 unicode 字符串,而在 python 3.x 中,小的 u 会导致语法错误。
【问题讨论】:
-
@ubershmekel 您会推荐哪种解决方案?你的还是接受答案的?
-
我建议使用
u'',因为它现在在 python 3.3 中得到支持
标签: python python-3.x unicode python-2.x unicode-literals