title: Python: Only running exception block when try block fails
body: <p>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 f<strong>or emphasis I do not wish to run any portion of try if any line in try fails</strong> </p>
  
  <pre><code>x = 1
  y = 1
  
  
  try:  
      x = x+1
      print(x)
      x.append(1)
  except:
      print(x)
  </code></pre>
  
  <p>which returns</p>
  
  <pre><code>2
  2
  </code></pre>
  
  <p>instead of returning</p>
  
  <pre><code>1
  </code></pre>
  
  <p>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.</p>
  
  <p>any help is much appreciated </p>