Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop Condition Question
#1
I want to iterate over a loop until an OSError is thrown. That's it. What's the best way to do that. What I'm doing is using winreg.EnumKey to make a list of all sub-keys of a key. The function returns one key at a time. So, I need to loop it, increasing the index each time to enum all keys. How do I stop the loop at an OSError (which is what the docs recommend)?
Just to show some code (this is not how I want to do it)
i = 0
while i < 5:
    list = winreg.EnumKey(<key>, i)
    i += 1
I want something like
while not OSError:
    ....
But my limited understanding is causing errors.

Help is, as always, much appreciated.
malonn
Reply


Messages In This Thread
Loop Condition Question - by malonn - Jul-31-2018, 05:48 PM
RE: Loop Condition Question - by Vysero - Jul-31-2018, 05:57 PM
RE: Loop Condition Question - by malonn - Jul-31-2018, 06:27 PM
RE: Loop Condition Question - by ichabod801 - Jul-31-2018, 07:00 PM
RE: Loop Condition Question - by malonn - Jul-31-2018, 07:19 PM
RE: Loop Condition Question - by Vysero - Jul-31-2018, 08:29 PM
RE: Loop Condition Question - by malonn - Aug-01-2018, 01:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to run this loop but it skips all the condition vensilver 5 1,954 Feb-17-2022, 05:38 PM
Last Post: deanhystad
  A question about 'Event loop is closed' fc5igm 2 2,252 Oct-05-2021, 02:00 AM
Last Post: fc5igm
Exclamation question about input, while loop, then print jamie_01 5 2,704 Sep-30-2021, 12:46 PM
Last Post: Underscore
  for loop question KEYS 1 1,744 Oct-27-2020, 11:42 PM
Last Post: jefsummers
  Netmiko Loop question sc00ter 2 3,341 Oct-24-2020, 10:54 PM
Last Post: sc00ter
  while loop question KEYS 2 2,029 Sep-26-2020, 11:02 PM
Last Post: KEYS
  New to programming, loop question tomyan 1 1,660 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  while loop question spalisetty06 2 1,864 Aug-13-2020, 04:18 PM
Last Post: buran
  question about for loop Than999 5 2,514 Jun-09-2020, 02:16 PM
Last Post: Emekadavid
  else condition not called when if condition is false Sandz1286 10 5,929 Jun-05-2020, 05:01 PM
Last Post: ebolisa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020