【发布时间】:2021-05-17 16:31:02
【问题描述】:
我有这本字典(带有 Selenium 列表元素,其中包含定义一些元素属性的字符串数组):
#The dictionary has this structure.
{0: {0: ['string1', 'string2', 'string3']}, 1: {1: ['string1', 'string2', 'string3']}}
当我打印整个字典时,它具有这种结构并且我没有收到任何错误。 但是当我尝试访问某个键的特定值时(例如上例中的 string1):
myPath\for\the\file\file.py, line in function
print(myDictionary[0][0])
KeyError: 0
有人知道为什么它不起作用吗?
【问题讨论】:
-
密钥是
'0'还是0? -
调试的第一条规则:打印出问题的对象,看看结构是什么。执行 print(myDictionary) 并查看它的外观。
-
@Epsi95 只是
0 -
@ScienceSnake 刚刚做到了。有时我想知道,当我这么笨的时候,我是如何完成能够说话的壮举的。感谢您的帮助。
标签: python arrays selenium dictionary