title: Python - Running Command Based on Result of If Statement
body: <p>I am fairly new to Python and coming from a JavaScript background where I am familiar with capturing the output of a command (success, error) and chaining that result to indicate my application's next command. Is there an approach to do something similar in Python?</p>
  
  <p>For example, I am using the <code>gspread</code> package to interact with a Google Sheet. I am running the command <code>gc.open(*Name*)</code> that searches for a Google Sheet when provided a string <code>(*Name*)</code>, but if this does not return a value or if it returns an error as it currently does, <code>SpreadsheetNotFound:</code>, then I would create a sheet with <code>gc.create(*Name)</code> criteria. I was playing around with try/exception, but felt like I was approaching it incorrectly.</p>
  
  <p>This is what I'm hoping to achieve:</p>
  
  <pre><code>if (API Call Finds the Sheet):
  
      Set regression_output = sheet
  
  else:
  
      Set regression_output = creation of sheet with specified name
  </code></pre>
  
  <p>Current Code:</p>
  
  <pre><code>open_regression_output_sheet = gc.open(file_name)
  
  for value in open_regression_output_sheet:
      try:
          regression_output = print("Test")
      except:
          regression_output = print("Error")
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>SpreadsheetNotFound: 
  </code></pre>