gpt4 book ai didi

Python:创建 Unicode 字符串

转载 作者:太空狗 更新时间:2023-10-29 18:30:52 25 4
gpt4 key购买 nike

我在使用 Unicode 的 Python 中遇到问题。我需要绘制一个带有 Unicode 注释的图形。根据tutorial我应该只用 Unicode 创建我的字符串。我这样做:

annotation = u"%s has %s rev"%(art.title, len(art.revisions))

它是 art.title 里面有 Unicode 字符。有时该代码有效,有时它会给我以下错误:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)

我该如何解决?

编辑:我在“注释”行之后有错误:

  File "script.py", line 195, in test_trie
annotation = u"%s has %s rev"%(art.title, len(art.revisions))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)

最佳答案

我认为这取决于您的标题是否包含 unicode 字符。

我会尝试添加 art.title.encode("utf-8")art.title.decode("utf-8") 看看效果如何作品

关于Python:创建 Unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10238588/

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