title: How to check text file exists and is not empty in python
body: <p>I wrote a script to read text file in python.</p>
  
  <p>Here is the code.    </p>
  
  <pre><code>parser = argparse.ArgumentParser(description='script')    
  parser.add_argument('-in', required=True, help='input file',
  type=argparse.FileType('r'))
  parser.add_argument('-out', required=True, help='outputfile',
  type=argparse.FileType('w'))     
  args = parser.parse_args()    
  
  try:
      reader = csv.reader(args.in)
      for row in reader:
          print "good"
  except csv.Error as e:
      sys.exit('file %s, line %d: %s' % (args.in, reader.line_num, e))
  
  for ln in args.in:
      a, b = ln.rstrip().split(':')
  </code></pre>
  
  <p>I would like to check if the file exists and is not empty file but this code gives me an error.</p>
  
  <p>I would also like to check if program can write to output file. </p>
  
  <p><strong>Command:</strong>   </p>
  
  <pre><code>python script.py -in file1.txt -out file2.txt 
  </code></pre>
  
  <p><strong>ERROR:</strong></p>
  
  <pre><code>good
  Traceback (most recent call last):
    File "scritp.py", line 80, in &lt;module&gt;
      first_cluster = clusters[0]
  IndexError: list index out of range
  </code></pre>