title: how to reuse if checks in python
body: <p>i try to execute the commands as as little as possible or re-use the code</p>
  
  <pre><code>id = 12345
  state, result = commands.getstatusoutput('command -where "(fieldid eq ' + id + ') and (fieldname eq male)"')
  if state != 0:
          print "error"
          newstate, newcom =  commands.getstatusoutput('command -where "(fieldid eq ' + id + ') and (fieldType like child)"')
          if newstate != 0:
             print "need to create male child"
          else:
              anotherstate, anothercom = commands.getstatusoutput('command -where "(fieldid eq ' + id + ') and (fieldType like child)" -get FatherId')
              master = anothercom.split(' = ')[1]
              masterid = re.findall(r'\d{5}', master)[0]
              # this will return the fathers ID and now i wanna check if the father has a male child, here i would go back up at the first row and enter into the if statements again but now with this new id, but i dont know what to use to do that
              # state, result = commands.getstatusoutput('command -where "(fieldid eq ' + masterid + ') and (fieldname eq male)"')
              # if state != 0:
              #     print "error"
              #     newstate, newcom =  commands.getstatusoutput('command -where "(fieldid eq ' + masterid + ') and (fieldType like child)"')
              #     if fwstate != 0:
              #         print "need to create male child"
  
      else:
          print "male child exists"
  </code></pre>
  
  <p>i commented out the block that i would like to replace, dont know how or with what (make some reference to the first like to get back there but with another variable, masterid)</p>
  
  <p>use for loop? or define two functions?</p>
  
  <p>maybe also this diagram would help...
  <a href="http://s22.postimg.org/ufy89kzyp/python.jpg" rel="nofollow">http://s22.postimg.org/ufy89kzyp/python.jpg</a></p>