【发布时间】:2013-09-13 22:25:37
【问题描述】:
这是我的代码(我使用的是 python 2.7)
result = " '{0}' is unicode or something: ".format(mongdb['field'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 27: ordinal not in range(128)
看起来我从 mongodb 读取的字符串包含 unicode。它会抛出这个错误。如何修复它以将此 unicode 与自定义字符串 'is unicode or something:' 连接起来?
提前致谢
更新
result = u" '{0}' is unicode or something: ".format(mongdb['field'])
为我工作
【问题讨论】:
-
这是 Python 2 还是 Python 3?