OO Windows Registry API

Tim Couper drtimcouper at yahoo.co.uk
Thu Mar 29 10:11:08 CEST 2001


Benji

I would prefer this style of registry access. 

Comments:

1. reg[HKEY_LOCAL_MACHINE]['Software']['My App']

I'd prefer to see:

reg[HKEY_LOCAL_MACHINE]['Software\My App'] or,
perhaps, more Pythonesquely
 
reg[HKEY_LOCAL_MACHINE]['Software','My App']

2. What about a AddKey-type of method:

CurrentKey=reg[HKEY_LOCAL_MACHINE] ....
CurrentKey.AddKey('foo')

> 
> 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


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie




More information about the Python-list mailing list