How is the simpler way to verify if the value is already created or create Windows registry values ?
2 Answers
Use the standard Python library module _winreg (it's renamed to winreg, no leading _, if you're using Python 3).
You always start with one of the constant keys named _winreg.HKEYsomething; to see them all, do:
>>> import _winreg
>>> [k for k in dir(_winreg) if k.startswith('HKEY')]
and repeatedly use (to navigate down the keys' tree) functions such as _winreg.Openkey (in a try/except to catch the WindowsError it raises when a key is not present).
1 Comment
Alex Martelli
So it's
_winreg, as I said first (most people are on Python 2.something, and _winreg is how the module is named from Python 2.0 to 2.7).