I am having trouble understanding how to write a try except block that only runs one block or the other not just half the block and then move to the exception as seen in my example for emphasis I do not wish to run any portion of try if any line in try fails
x = 1
y = 1
try:
x = x+1
print(x)
x.append(1)
except:
print(x)
which returns
2
2
instead of returning
1
as I would of expected. This is problematic for me because I was foolishly under the impression that only except block would be executed upon try failure. I am scraping websites using beautiful soup and my allocation of a soup usually will throw the exception and the other block will run but unforeseen errors after this allows some lists to be appended then runs the exception block and appends them again. leaving me with lists of different lengths depending on where they fall within each block.
any help is much appreciated