关于值类型:http ://docs.python.org/2/library/_winreg.html#value-types
如何_winreg.REG_BINARY
查询'REG_BINARY'
?
我可以通过以下方式手动完成:
import _winreg
reg_type_str = {
_winreg.REG_BINARY: 'REG_BINARY',
_winreg.REG_DWORD: 'REG_DWORD',
_winreg.REG_DWORD_LITTLE_ENDIAN: 'REG_DWORD_LITTLE_ENDIAN',
_winreg.REG_DWORD_BIG_ENDIAN: 'REG_DWORD_BIG_ENDIAN',
_winreg.REG_EXPAND_SZ: 'REG_EXPAND_SZ',
_winreg.REG_LINK: 'REG_LINK',
_winreg.REG_MULTI_SZ: 'REG_MULTI_SZ',
_winreg.REG_NONE: 'REG_NONE',
_winreg.REG_RESOURCE_LIST: 'REG_RESOURCE_LIST',
_winreg.REG_FULL_RESOURCE_DESCRIPTOR: 'REG_FULL_RESOURCE_DESCRIPTOR',
_winreg.REG_RESOURCE_REQUIREMENTS_LIST: 'REG_RESOURCE_REQUIREMENTS_LIST',
_winreg.REG_SZ: 'REG_SZ',
}
reg_type_str.get(_winreg.REG_SZ)
肯定有更好的方法吗?
我正在尝试做的...
示例查询:
reg_data, reg_type = _winreg.QueryValueEx(key, reg_value)
log.debug("Query: %s [%d:%s]" % (reg_data, reg_type, reg_type_str.get(reg_type)))
我想我应该能够做这样的事情:
>>> for k, v in _winreg.__dict__:
... if v == _winreg.REG_SZ:
... print k
Traceback (most recent call last):
File "<pyshell#468>", line 1, in <module>
for k, v in _winreg.__dict__:
ValueError: too many values to unpack
当然,这是行不通的,但即使这样做了,这种方法在与 _winreg 一起使用时也会导致问题:
>>> for v in _winreg.__dict__.itervalues():
... if v == _winreg.REG_SZ:
... print v
1
1
1
1
1
1