gpt4 book ai didi

python - unicode在哪里?

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:18 25 4
gpt4 key购买 nike

使用 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

最佳答案

您需要显式编码 phrase unicode 值:

print("Here is a phrase: " + phrase.encode('some_codec'))
unicode 值上的

str() 使用默认编解码器(Python 2 上的 ASCII)隐式编码该值。

关于python - unicode在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17045700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com