使用Python模块unicode-nazi来检测unicode问题,我遇到了这个警告:
/home/dotancohen/unicode-test.py:51:UnicodeWarning:将unicode隐式转换为str
print("这是一个短语:"+ str(短语))
由于phrase是显式转换为字符串,隐式转换在哪里?肯定"Here is a phrase: "是一个字符串,因为它没有前面u.
您需要phrase显式编码unicode值:
print("Here is a phrase: " + phrase.encode('some_codec'))
Run Code Online (Sandbox Code Playgroud)
str() 在unicode值上使用默认编解码器(Python 2上的ASCII)隐式编码该值.
| 归档时间: |
|
| 查看次数: |
176 次 |
| 最近记录: |