Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 31st March 2009
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
Join Date: Apr 2008
Location: Dutchman living in the UK
Posts: 2,199
Default Python: Use the value of a variable for calling another variable

My code (simplified):

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

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:

>>> import _winreg
>>> print _winreg.HKEY_LOCAL_MACHINE
>>> 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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
apache with python deadeyes FreeBSD Ports and Packages 1 27th August 2009 01:31 PM
CSH 'mch' variable? JMJ_coder General software and network 1 12th February 2009 11:24 PM
wip/kdebindings4-python errors Cloud NetBSD Package System (pkgsrc) 7 17th January 2009 06:52 PM
py-yaml - Python 2.5 and 2.6 iGloo FreeBSD Ports and Packages 0 20th December 2008 08:36 PM
Using Date variable? cwhitmore FreeBSD General 9 13th August 2008 07:16 AM

All times are GMT. The time now is 09:16 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick