title: Checking data in a csv file using python
body: <p>I am uploading a csv file and I want to check this file line by line using a python script to ensure that all the input id's match. This file contains object types, definitions and actions along with an input Id. When anyone enters the input Id and the path to their file on the command line next to the script, the script should run if the file exists and the input id matches the input Id in their file. if not I want to issue an error for them to check the id again? How can I do this?</p>
  
  <p>This is the data and the expected output. I'm creating this along with a TIMESTAMP log to check that the information that was put in is correct. When the script starts it will go line by line and check that the input id is the right one so that no one fat fingers in the wrong id. Here is how the data looks: </p>
  
  <pre class="lang-none prettyprint-override"><code>Action  Object Type   Input ID
  Add:    House Group   HG-Site-PIC
  Add:    Service Team  HG-Site-PIC
  Add:    Service       HG-Site-PIC
  Modify
  Modify
  Modify
  Delete
  Delete
  Delete
  </code></pre>
  
  <p>My code so far:</p>
  
  <pre><code>import csv
  import sys
  import os
  
  def check_all(f):
      print f.read()
  
  def print_a_line(line_count, f):
      print line_count, f.readline()
  
  try:
      current_file = open(input_file)
      check_all(current_file)
  except IOError, e:
      print '%s, please try again.' % e
  
  ifile = open('file_name', "rb")
  reader = csv.reader(ifile)
  ofile = open('file_name', "wb")
  writer = csv.writer(ofile, delimiter='\t', quotechar=' ',quoting=csv.QUOTE_ALL)
  
  for row in reader:
      writer.writerow(row)
  
  ifile.close()
  ofile.close()
  </code></pre>