Not cathing nested StopIteration

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Jul 21 04:32:36 EDT 2017


This is python 3.4 on a debian box
In the code below, line 36 raises a StopIteration, I would have
thought that this exception would be caught by line 39 but instead
I get a traceback.
Did I miss something or is this a bug?
This is the code:
 try: # 21
 filename = os.path.join(lang_path, lang) # 22
 fl = open(filename) # 23
 except FileNotFoundError: # 24
 try: # 25
 lst = lang.split('_') # 26
 prefix = lst[0] + '*' # 27
 try: # 28
 lst[1] = lst[0].upper() # 29
 except IndexError: # 30
 lst.append(lst[0].upper()) # 31
 lang = '_'.join(lst) # 32
 filename = os.path.join(lang_path, lang) # 33
 fl = open(filename) # 34
 except FileNotFoundError: # 35
 lang = next(iglob(os.path.join(lang_path, prefix))) # 36
 filename = os.path.join(lang_path, lang) # 37
 fl = open(filename) # 38
 except StopIteration: # 39
 fl = () # 40
This is the traceback:
Traceback (most recent call last):
 File "/home/antoon/src/projecten/richter/translate.py", line 23, in use_lang
 fl = open(filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/antoon/src/projecten/richter/locus/nl'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "/home/antoon/src/projecten/richter/translate.py", line 34, in use_lang
 fl = open(filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/antoon/src/projecten/richter/locus/nl_NL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "lang_test", line 4, in <module>
 use_lang("Nederlands")
 File "/home/antoon/src/projecten/richter/translate.py", line 36, in use_lang
 lang = next(iglob(os.path.join(lang_path, prefix)))
StopIteration
-- 
Antoon.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /