View Single Post
  #1   (View Single Post)  
Old 31st March 2009
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default Python: Use the value of a variable for calling another variable

My code (simplified):

Code:
import _winreg as winreg

SetRegistry(winreg.HKEY_LOCAL_MACHINE, key, values)

def SetRegistry(reg, key, values):
  reghandle = winreg.ConnectRegistry(None, reg)
This works, but I would like to pass HKEY_LOCAL_MACHINE as a string because I want to make a backup of changed registry settings, but how do I pass this on to ConnectRegistry? This for example won't work for obvious reasons (changes in red):

Code:
import _winreg as winreg

SetRegistry('HKEY_LOCAL_MACHINE', key, values)

def SetRegistry(reg, key, values):
  reghandle = winreg.ConnectRegistry(None, winreg.reg)
Unfortunately, I can't use __str__(), since it's just an int:

Code:
>>> import _winreg
>>> print _winreg.HKEY_LOCAL_MACHINE
2147483650
>>> type(_winreg.HKEY_LOCAL_MACHINE)
<type 'long'>
Probably missing something simple ... :-/
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote