Python嵌套字典,检查3个不同版本是否与键和值兼容

托金

我在论坛上找不到类似的解决方案,如果错过了,抱歉。我用view_version:os_name:driver-version构建了一个嵌套字典,我试图根据与os_name和os_name对应的view_version来检查view_version,os_name和驱动程序版本(是否已从日志文件中解析出所有3个版本)是否兼容。字典中的driver_version。这样做的最佳方法是我尝试访问键和值并进行比较,但似乎无法正常工作或出现任何错误。python和dictionary的新手。让我知道是否需要对其进行编辑并使其更加清晰。先感谢您

version_dict = {}
version_dict = {'view 3.1.3': {'windows XP':'11.6.0.35', 'windows vista': '17.14.1.42',     'windows 7': 'not supported', 'windows 8':'not supported', 'windows 8.1' : 'not supported','windows server 20008 R2':'not supported'},
'view 4.0.2':{'windows xp': '11.6.0.35','windows vista': 'not supported','windows 7': 'not supported','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'},
'view 4.5.0':{'windows xp': '11.6.0.37','windows vista': '11.6.0.37','windows 7': '7.14.1.49','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'},
'view 4.6.0':{'windows xp': '11.6.0.37','windows vista': '11.6.0.37','windows 7': '7.14.1.49','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 4.6.3':{'windows xp': '11.6.0.39','windows vista': 'not supported','windows 7': '7.14.1.1052','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.0':{'windows xp': '11.7.5.0','windows vista': '11.7.5.0','windows 7': '7.14.1.1061','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.0.1':{'windows xp': '11.7.5.0','windows vista': '11.7.5.0','windows 7': '7.14.1.1063','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.1.0':{'windows xp': '11.7.20.0','windows vista': 'not supported','windows 7': '7.14.1.1080','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.1.1':{'windows xp': '11.6.0.35','windows vista': 'not supported','windows 7': 'not supported','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.1.2':{'windows xp': '11.7.20.0','windows vista': 'not supported','windows 7': '7.14.1.1208','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.1.3':{'windows xp': '11.7.20.0','windows vista': 'not supported','windows 7': '7.14.1.1.1208','windows 8': 'not supported','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.2.0':{'windows xp': '11.7.20.0','windows vista': 'not supported','windows 7': '7.14.1.1235','windows 8': '7.14.1.1235','windows 8.1': 'not supported', 'windows server 2008 R2': 'not supported'}, 
'view 5.3.0':{'windows xp': '12.0.23.0','windows vista': 'not supported','windows 7': '7.14.1.2021','windows 8': '7.14.1.2021','windows 8.1': '7.14.1.2021', 'windows server 2008 R2': '7.14.1.2021'}, 
'view 5.3.1':{'windows xp': '12.0.23.0', 'windows vista': 'not supported', 'windows 7': '7.14.1.2021','windows 8': '7.14.1.2021','windows 8.1': '7.14.1.2021', 'windows server 2008 R2': '7.14.1.2021'},
'view 6.0':{'windows xp': '12.0.23.0', 'windows vista': 'not supported', 'windows 7': '7.14.1.2032', 'windows 8': '7.14.1.2032', 'windows 8.1': '7.14.1.2032', 'windows server 20008 R2': '7.14.1.2032'}}
            if view_version in version_dict.keys:
                if os_name in version_dict[view_version].keys:
                    if version == version_dict[os_name]:
                        print 'The display driver version'+ version+ 'is compatible with the current'+view_version+'and'+os_name
                    else:
                        print 'The display driver version'+version+ 'is not compatible with the current'+view_version+ 'and'+ os_name
范罗杰

dict.keys是一个函数,而不是一个属性。所以所有这些检查应该像

if view_version in version_dict.keys():
    ...

注意后面的括号keys表示函数调用。

另外,我不知道这是复制粘贴错误还是其他错误,但是底部代码段的缩进是不正确的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

执行之前检查python版本是否与脚本兼容

来自分类Dev

在python中检查键,嵌套字典的值?

来自分类Dev

检查SVN版本是否不同

来自分类Dev

Python 2和3兼容的键和值迭代字典的方式

来自分类Dev

根据列表检查嵌套字典python中是否存在键

来自分类Dev

嵌套字典键和值

来自分类Dev

字典:检查键和值的每个元素是否相等

来自分类Dev

字典和嵌套字典之间的Python键匹配,并将新值写入嵌套字典

来自分类Dev

检查Python字典中是否存在键/值对

来自分类Dev

检查Python字典是否具有相同的形状和键

来自分类Dev

检查 iOS 版本是否兼容从 iOS 3.0 到 IOS 4.0 或更高版本的 PHP

来自分类Dev

如何检查版本是否大于某个基本值?

来自分类Dev

将两个嵌套字典的键相同,但字典的值不同

来自分类Dev

Python嵌套字典从嵌套值检索键

来自分类Dev

字典-检查值是否具有键

来自分类Dev

如何检查字典中是否存在键值对?如果一个键的值是字典

来自分类Dev

Python3在嵌套字典和列表中按值搜索,然后获取其他最近的键/值对

来自分类Dev

在字典中分配嵌套键和值

来自分类Dev

在字典中分配嵌套键和值

来自分类Dev

从嵌套字典中删除键和值?

来自分类Dev

检查Bash脚本是否与sh兼容

来自分类Dev

比较另一个嵌套字典中一个嵌套字典的键和值

来自分类Dev

python检查多级字典键是否存在

来自分类Dev

python:将两个嵌套字典与字典组合为顶级键的值

来自分类Dev

python:将两个嵌套字典与字典组合为顶级键的值

来自分类Dev

Python嵌套字典键,值交换

来自分类Dev

在3个不同的字典中查找MIN和MAX值

来自分类Dev

在3个不同的字典中查找MIN和MAX值

来自分类Dev

如何仅在字典中存储键的3个值?Python

Related 相关文章

  1. 1

    执行之前检查python版本是否与脚本兼容

  2. 2

    在python中检查键,嵌套字典的值?

  3. 3

    检查SVN版本是否不同

  4. 4

    Python 2和3兼容的键和值迭代字典的方式

  5. 5

    根据列表检查嵌套字典python中是否存在键

  6. 6

    嵌套字典键和值

  7. 7

    字典:检查键和值的每个元素是否相等

  8. 8

    字典和嵌套字典之间的Python键匹配,并将新值写入嵌套字典

  9. 9

    检查Python字典中是否存在键/值对

  10. 10

    检查Python字典是否具有相同的形状和键

  11. 11

    检查 iOS 版本是否兼容从 iOS 3.0 到 IOS 4.0 或更高版本的 PHP

  12. 12

    如何检查版本是否大于某个基本值?

  13. 13

    将两个嵌套字典的键相同,但字典的值不同

  14. 14

    Python嵌套字典从嵌套值检索键

  15. 15

    字典-检查值是否具有键

  16. 16

    如何检查字典中是否存在键值对?如果一个键的值是字典

  17. 17

    Python3在嵌套字典和列表中按值搜索,然后获取其他最近的键/值对

  18. 18

    在字典中分配嵌套键和值

  19. 19

    在字典中分配嵌套键和值

  20. 20

    从嵌套字典中删除键和值?

  21. 21

    检查Bash脚本是否与sh兼容

  22. 22

    比较另一个嵌套字典中一个嵌套字典的键和值

  23. 23

    python检查多级字典键是否存在

  24. 24

    python:将两个嵌套字典与字典组合为顶级键的值

  25. 25

    python:将两个嵌套字典与字典组合为顶级键的值

  26. 26

    Python嵌套字典键,值交换

  27. 27

    在3个不同的字典中查找MIN和MAX值

  28. 28

    在3个不同的字典中查找MIN和MAX值

  29. 29

    如何仅在字典中存储键的3个值?Python

热门标签

归档