PythonWin: Strange Debugger Behavior
Charles Medcoff
cmedcoff at sprynet.com
Sat May 22 19:46:46 EDT 1999
The script below exhibits inconsistent behavior under the PythonWin
Debugger. The first time I step through it runs until an exception happens
on the line " self._key = RegOpenKeyEx(self._hive, subkey)" (because of a
missing key from the registry on my machine?). If I restart the debugging
process I observe a difference behavior. The call to RegKey.__init__(...)
is immediatlely followed by a call to RegKey.__del__(). The happens before
the print statement (the line following the constructor call) and perhaps
even before the assignment. The call to __del__() also throws an exception
(because the attiribute _key has not yet been created?). Comments.
from win32con import HKEY_CURRENT_USER
from win32con import HKEY_LOCAL_MACHINE
from win32api import RegOpenKeyEx
from win32api import RegQueryValueEx
from win32api import RegQueryInfoKey
from win32api import RegEnumKey
from win32api import RegEnumValue
#######################################################################
# classes
#######################################################################
class RegKey:
HKEY_CURRENT_USER = 0x80000001
HKEY_LOCAL_MACHINE = 0x80000002
def __init__(self, hive):
_hive = hive
def open(self, subkey):
self._subkey = subkey
self._key = RegOpenKeyEx(self._hive, subkey)
def value(self, val):
self._val = RegQueryValueEx(self._key, path)
return self._val[0]
def __del__(self):
self._key.Close()
#######################################################################
# main - for testing
#######################################################################
if __name__ == '__main__':
testkey = RegKey(RegKey.HKEY_LOCAL_MACHINE)
print testkey
testkey.open('SOFTWARE\Microsoft\DrWatson')
print testkey.value('ProductDir')
More information about the Python-list
mailing list