Robot框架中的Convert To Dictionary出现错误“ValueError:字典更新序列元素#0的长度为1;需要2”

2024-05-21 03:46:11 发布

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

我似乎找不到Convert to Dictionary关键字的任何示例,因此我不确定如何使用它

以下代码:

 ${newdomain_dict}                 Convert To Dictionary   {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} 

给出错误“ValueError:字典更新序列元素#0的长度为1;需要2”

文档只是说这个关键字有一个参数(item),所以我不确定这个“item”是什么意思——我假设是一个字符串。甚至当我在github上查看源代码时,我也得到了这样的印象


Tags: to代码id示例convertdictionaryxmppmsg
1条回答
网友
1楼 · 发布于 2024-05-21 03:46:11

这是因为参数{'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']}被视为字符串

该关键字的文档说明如下:

Mainly useful for converting other mappings to normal dictionaries.

字符串不是映射类型

如果希望通过字符串定义字典,可以使用robot的inline python evaluation

${newdomain_dict}  ${{ {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} }}

相关问题 更多 >