Skip to content
Advertisement

Tag: except

Python: Multiple try except blocks in one?

Is there a neat way to have multiply commands in the try block so that it basically tries every single line without stopping as soon as one command yields an error? Basically I want to replace this: with this: Defining a list so I could loop through the commands seems to be a bad solution Answer I’d say this is

Multiple try codes in one block

I have a problem with my code in the try block. To make it easy this is my code: Is something like this possible? Answer You’ll have to make this separate try blocks: This assumes you want to run code c only if code b failed. If you need to run code c regardless, you need to put the try

Advertisement