title: Correct way to check for empty or missing file in Python
body: <p>I want to check both whether a file exists and, if it does, if it is empty.</p>
  
  <p>If the file doesn't exist, I want to exit the program with an error message.</p>
  
  <p>If the file is empty I want to exit with a different error message.</p>
  
  <p>Otherwise I want to continue.</p>
  
  <p>I've been reading about using Try: Except: but I'm not sure how to structure the code 'Pythonically' to achieve what I'm after?</p>
  
  <hr>
  
  <p>Thank you for all your responses, I went with the following code:</p>
  
  <pre><code>try:
      if os.stat(URLFilePath + URLFile).st_size &gt; 0:
          print "Processing..."
      else:
          print "Empty URL file ... exiting"
          sys.exit()
  except OSError:
      print "URL file missing ... exiting"
      sys.exit()
  </code></pre>