[英]Convert To Dictionary in Robot Framework gives the error “ValueError: dictionary update sequence element #0 has length 1; 2 is required”
I cannot seem to find any examples for the Convert To Dictionary keyword so I am not really sure on how to use it.我似乎找不到任何转换为字典关键字的示例,所以我不确定如何使用它。
The following code:以下代码:
${newdomain_dict} Convert To Dictionary {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']}
gives the error "ValueError: dictionary update sequence element #0 has length 1; 2 is required"给出错误“ValueError:字典更新序列元素 #0 的长度为 1;需要 2”
The documentation just says this keyword has one argument (item), so I am not sure what this "item" is meant to be - I assumed a string.文档只是说这个关键字有一个参数(项目),所以我不确定这个“项目”是什么意思 - 我假设一个字符串。 Even when I looked on github at the source code this is the impression I got.即使我在源代码中查看 github,这也是我得到的印象。
This is because the argument {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']}
is treated as a string.这是因为参数{'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']}
被视为字符串。
The documentation for that keyword says this:该关键字的文档是这样说的:
Mainly useful for converting other mappings to normal dictionaries.主要用于将其他映射转换为普通字典。
A string is not a mapping type.字符串不是映射类型。
If you're wanting to define a dictionary via a string, you can use robot's inline python evaluation .如果您想通过字符串定义字典,可以使用机器人的内联 python 评估。
${newdomain_dict} ${{ {'id': 'newdomain', 'entityTypes': ['users', 'msg', 'xmpp']} }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.