使用Python模块unicode-nazi来检测unicode问题,我遇到了以下警告:
/home/dotancohen/unicode-test.py:51: UnicodeWarning: Implicit conversion of unicode to str
print("Here is a phrase: " + str(phrase))
既然phrase
正被显式地转换为字符串,那么隐式转换在哪里?当然,"Here is a phrase: "
是一个字符串,因为它前面没有u
。在
Tags:
您需要显式地编码
phrase
unicode值:unicode值上的
str()
使用默认的编解码器(python2上的ASCII)隐式地对该值进行编码。在相关问题 更多 >
编程相关推荐