我在读取windows 7 winth winreg模块的注册表值时遇到问题。有没有解决相同问题的指针?在
代码:
try:
ParentKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")
i = 0
while 1:
name, value, type = _winreg.EnumValue(ParentKey, i)
print repr(name),
i += 1
except Exception as e:
print(Exception(e))
ParentKey =_winreg.DisableReflectionKey(ParentKey)
temp = _winreg.QueryValueEx(ParentKey, 'DisplayName')
temp1 = _winreg.QueryValueEx(ParentKey, 'DisplayVersion')
temp2 = _winreg.QueryValueEx(ParentKey, 'Publisher')
temp3 = _winreg.QueryValueEx(ParentKey, 'InstallLocation')
display = str(temp[0])
display_ver=str(temp1[0])
display_p=str(temp2[0])
display_loc=str(temp3)
print ('Display Name: ' + display + '\nDisplay version: ' + display_ver + '\nVendor/Publisher: ' + display_p +'\nRegkey: ' + display_loc +'\nInstall Location: ' )
输出:
^{pr2}$
这条线:
将返回
None
。函数DisableReflectionKey
没有记录为返回任何内容(成功或失败由是否引发异常来指示)。这种不返回任何内容的函数隐式返回None
。由于您将返回值绑定到ParentKey
,因此该变量将从该点起保存None
。在所以,当然,接下来的电话
^{pr2}$将失败,因为
QueryValueEx
需要定义的键(而不是None
)才能工作。在相关问题 更多 >
编程相关推荐