The main problem is that your try suggestions are too wide, especially the most distant ones: you will sooner or later encounter a mysterious mistake because one of your attempts / exceptions accidentally hid an unexpected bubble exception from some other the function you are calling.
Therefore, I would suggest instead:
for app in apps: if app.split('.', 1)[0] != 'zc':
As an aside, I also apply “flat better than nested” in a different way (independent of any try / except), that “if I have nothing more to do on this leg of the loop, continue [ie move on to the next leg of the loop] instead of “if I need to do something,” followed by a significant amount of nested code. I always preferred this style (if / continue or if / return) for nested if in languages that supply functions such as continue (by essentially all modern, since C has this ;-).
But this is a simple “flat versus nested” style, and the problem is that you keep your suggestions. In the worst case scenario, when you simply cannot just continue or return in the except clause, you can use try / except / else: put in the try clause only what absolutely SHOULD be there - a tiny piece of code that is likely to be raised - and add the rest of the following code (the part that is NOT allowed and should not be raised) in the else clause. This does not change nesting, but it makes a huge difference in reducing the risk of accidentally hiding exceptions that are NOT expected!
source share