winreg module, need help to understand why i'm getting exception

2008-04-19 Thread hellt
HI all, i found winreg module from 
http://www.rutherfurd.net/python/winreg/index.html
very useful and simple, instead _winreg.

But i have a problem with this module, in its iterable part.

look at the following code

key = Key(HKLM,rSYSTEM\CurrentControlSet\Services\Tcpip\Enum)
for i in key.values:
print i.value

and that is the exception

Traceback (most recent call last):
 File D:\.Projects\python\temp.py, line 21, in module
   for i in key.values:
 File C:\Python25\Lib\site-packages\winreg.py, line 451, in next
   return self.values[self.index - 1]
 File C:\Python25\Lib\site-packages\winreg.py, line 289, in
__getitem__
   name = _winreg.EnumValue(self.hkey, key)[0]
WindowsError: [Error 259] No more data is available


so there is some problem with iterate, i think
i am still a beginner, so i cant understand why this appears, and what
should i fix.

if anyone have some time to look closer to this module, i will
appreciate this very much.

thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: winreg module, need help to understand why i'm getting exception

2008-04-19 Thread s0suk3
On Apr 19, 6:20 am, hellt [EMAIL PROTECTED] wrote:
 HI all, i found winreg module 
 fromhttp://www.rutherfurd.net/python/winreg/index.html
 very useful and simple, instead _winreg.

 But i have a problem with this module, in its iterable part.

 look at the following code

 key = Key(HKLM,rSYSTEM\CurrentControlSet\Services\Tcpip\Enum)
 for i in key.values:
 print i.value

 and that is the exception

 Traceback (most recent call last):
  File D:\.Projects\python\temp.py, line 21, in module
for i in key.values:
  File C:\Python25\Lib\site-packages\winreg.py, line 451, in next
return self.values[self.index - 1]
  File C:\Python25\Lib\site-packages\winreg.py, line 289, in
 __getitem__
name = _winreg.EnumValue(self.hkey, key)[0]
 WindowsError: [Error 259] No more data is available

 so there is some problem with iterate, i think
 i am still a beginner, so i cant understand why this appears, and what
 should i fix.

 if anyone have some time to look closer to this module, i will
 appreciate this very much.

The problem is not in your code, but in the module. The EnumValue()
and EnumKey() functions in the _winreg module raise WindowsError when
there are no more keys or values to retrieve. So, go inside the module
and modify that line to something like:

# There should be a for or a while loop around here
try:
name = _winreg.EnumValue(key, index)
except EnvironmentError:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: winreg module, need help to understand why i'm getting exception

2008-04-19 Thread s0suk3
Sorry, the above post is not complete. This is the rest:

# There should be a for or a while loop around here
try:
name = _winreg.EnumValue(key, index)
except EnvironmentError:
# It raises WindowsError, but the _winreg documentation
# recommends catching EnvironmentError
break
else:
# do something with 'name'
...

Anyway, I'd recommend using _winreg instead of the module you're
using, since it clearly has errors, and it's not on the standard
library.
-- 
http://mail.python.org/mailman/listinfo/python-list