python - 字典字典:TypeError:列表索引必须是整数,而不是 unicode
问题描述
我的目标是拥有一个包含字符串作为键和其他字典作为值的字典。
所以我构建了下面的代码来迭代所有值。
但是,我面临错误:TypeError: list indices must be integers, not unicode
。
*** Test Cases ***
...
:FOR ${element} IN @{elements}
\ ${elementDictionary}= Create Dictionary
\ Set To Dictionary ${elementDictionary} k1 ${v1}
\ Set To Dictionary ${elementDictionary} k2 ${v2}
\ Set To Dictionary ${elementDictionary} k3 ${v3}
\ Set To Dictionary ${elementsDictionary} ${k} ${elementDictionary}
END
:FOR ${elementKey} IN @{elementsDictionary}
\ @{element}= Get From Dictionary ${elementsDictionary} ${elementKey}
\ Browse Dictionary Value @{element}
\ Log To Console ----------------------
END
*** Keywords ***
Browse Dictionary Value
[Arguments] @{dictionary}
:FOR ${key} IN @{dictionary}
\ ${value}= Get From Dictionary ${dictionary} ${key}
\ Log To Console ${key}
\ Log To Console ${value}
END
错误发生在以下行:${value}= Get From Dictionary ${dictionary} ${key}
请你帮助我好吗?十分感谢。
解决方案
用来${element}
代替@{element}
解决方案
用于Get Dictionary Keys
获取字典键并循环该列表而不是@{dictionary}
该Browse Dictionary Value
关键字。
推荐阅读
- python - use custom functions in transform_calculate in altair
- selenium-webdriver - Starting Edge Chromium in InPrivate mode / headless mode did not work for selenium
- javascript - what features of Google Analytics can be used in Electron-Vue application
- x11-forwarding - Snap applications through a remote X11 session
- java - Bean initialized with FactoryBean receives the FactoryBean instead of the Obect created by it
- python - How can I change the data type to run the program faster?
- reactjs - How to use react to implement google Place's Searches, to create markers on the map?
- javascript - Sweetalert Validation null control
- android - 显示和字体较大时手动计算可用宽度不正确
- python - 向量的 Keras 二进制精度