OO Windows Registry API
york at ficom.net
york at ficom.net
Wed Mar 28 11:49:34 EST 2001
After using the _winreg module I was pining for the fjords -- oh, sorry -- I was pining for a more Pythonesc API. I noticed that the Python documentation mentions that a better API may be written in the future, but none has been forthcoming. So -- while up at 2AM with my 6-week-old son last night -- I wrote a wrapper that exposes the registry as a dictionary-like object. It seems to work really well, and more importantly it feels more like a Python module should.
I decided to search Python-Dev for mentions of a higher-level API and found a squabble over various proposals. Did the idea of an OO interface die last August, or is there any interest in what I've done?
(Untested) Example code:
from winreg import Registry, NewKey, HKEY_CURRENT_USER
reg = Registry()
# Create a new "My App" key under HKEY_CURRENT_USER/Software.
reg[HKEY_CURRENT_USER]['Software']['My App'] = NewKey()
# Add some values to the newly created key.
# Note: the module only supports strings right now, but that's
# easy to change.
reg[HKEY_CURRENT_USER]['Software']['My App']['foo'] = 'value 1'
reg[HKEY_CURRENT_USER]['Software']['My App']['bar'] = 'value 2'
# Create a new subkey.
reg[HKEY_CURRENT_USER]['Software']['My App']['subkey'] = NewKey()
# Delete a value.
del reg[HKEY_CURRENT_USER]['Software']['My App']['foo']
# Delete a key.
del reg[HKEY_CURRENT_USER]['Software']['My App']
Any comments or suggestions? If anyone is interested in the code, I'll post it on the web.
--
Benji York
york at ficom.net
==================================
Posted via http://nodevice.com
Linux Programmer's Site
More information about the Python-list
mailing list