[Tutor] Resuming one block of code continuously after exception in try/except construction

Alan Gauld alan.gauld at btinternet.com
Mon Jul 7 01:34:03 CEST 2014


On 07/07/14 00:28, Alan Gauld wrote:

> Drop the else clause and put the try/except inside a while...
>
> def makelgpwdcombs(brutelistname):
>      while True:
>        try:
>         blst = open(brutelistname, 'r')
>            break # exit loop if no error

oops, indentation error there. Sorry
       while True:
           try:
              blst = open(brutelistname, 'r')
              break # exit loop if no error

>         except:
>            print("[-] Invalid file name or insufficient priviliges")
>
>      print("[+] File opened. Working...")   # only after valid input


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list