如何修复“translate()获取意外的关键字参数”format“”

2024-04-29 13:43:07 发布

您现在位置:Python中文网/ 问答频道 /正文

当我翻译返回撇号的文本时,我遇到了一个问题 en: "this is me" == fr: "c'est moi",但我得到{}。 为此,我想指定文本的格式,但当我执行脚本时,我得到:

TypeError: translate() got an unexpected keyword argument 'format'
^{pr2}$

Tags: 文本脚本anis格式frthistranslate
1条回答
网友
1楼 · 发布于 2024-04-29 13:43:07

如果要为format提供参数,则必须使用format_,它接受可选参数:[github code]

:type format_: str

:param format_: (Optional) One of text or html, to specify if the input text is plain text or HTML.

但是,这是针对输入文本而不是输出文本。如果您想转换回一个真正的撇号,您可以使用html.unescape,因为返回的是字符的html表示:[docs]

import html
print(html.unescape(text))

相关问题 更多 >