我在论坛上找不到类似的解决方案,如果错过了,抱歉。我用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] 删除。
我来说两句