Hi all,
I received an email the other day requesting me to verify some code.
The code was this...
Honestly, I'm a total beginner at this kind of thing.
It looks to me as though the code is to determine between an automated and user connection but I wouldn't be surprised to find out I'm totally wrong.
I think near the end there's a : that should be a ; but then aside from that, I can't really find any obvious issues.
I was hoping for some guidance or advice really. Somewhere I can start from to solve the problem and answer the questions.
Thanks,
I received an email the other day requesting me to verify some code.
The code was this...
import _winreg class RegistryError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) def getRegistryFoldersUnderParent(registry_connection, parent_folder): all_folders = "" try: if registry_connection == "machine": a_reg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE) elif registry_connection == "user": a_reg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER) else: raise RegistryError("Unknown registry connection type %s. Must be 'machine' or 'user'" % registry_connection) parentKey = _winreg.OpenKey(a_reg, parent_folder) except WindowsError as ex: raise RegistryError(ex) # Start on the second entry, so i=1 at start i = 0 while True: try: key = _winreg.EnumKey(parentKey, i) all_folders+=key + " ;" i += 1 except WindowsError as ex: break all_folders = all_folders[:-2] return all_foldersI was asked what does the code do? What is wrong with it? and are there any improvements to be made?
Honestly, I'm a total beginner at this kind of thing.
It looks to me as though the code is to determine between an automated and user connection but I wouldn't be surprised to find out I'm totally wrong.
I think near the end there's a : that should be a ; but then aside from that, I can't really find any obvious issues.
I was hoping for some guidance or advice really. Somewhere I can start from to solve the problem and answer the questions.
Thanks,