Feb-18-2018, 03:20 AM
a while back, in a discussion that involved try/except constructs, someone said that it was a bad idea to get out of a try/except with statements like return and continue. so i have been avoiding that by setting variables to indicate if i need to do something, then after the try/except, testing that variable and maybe doing that action.
i am cleaning up some code, today, that is like that. in a loop iterating over a list of files i perform os.lstat() on each file. if it fails i just want to skip that file. so my code looks like this:
anyone know what i should be doing? should i be reviewing all my existing code for try/except cases like this?
i am cleaning up some code, today, that is like that. in a loop iterating over a list of files i perform os.lstat() on each file. if it fails i just want to skip that file. so my code looks like this:
for fn in file_list: try: s = os.lstat(fn) x = False except: x = True if x: continue ...today this "bothered" me and i was wondering if i really needed to do that, or if i could simply do:
for fn in file_list: try: s = os.lstat(fn) except: continue ...which seems like the "right way" to do this.
anyone know what i should be doing? should i be reviewing all my existing code for try/except cases like this?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.