title: How do I search for text within a tab delimited file and print this information?
body: <p>I need to search for something in a tab delimited text file. The user is supposed to input both the file and the thing that needs searching for. The programme is then supposed to return the whole line that the user inputted word is in. I have got two models so far because I've been coming at this problem from different angles. The first programme goes as follows:</p>
  
  <pre><code>import csv
  
  searchfile = raw_input ('Which file do you want to search?   ')
  try:
      input_file = open (searchfile, 'rU')
  except:
      print "Invalid file. Please enter a correct file"
  
  csv_file_object = csv.reader(open(searchfile, 'rb')) 
  header = csv_file_object.next()   
  
  data=[]                          
  for row in csv_file_object:      
      data.append(row)             
  
  searchA = raw_input ('which author?')
  
  author_search = data[0::,0] == searchA
  
  if author_search in searchfile:
      print author_search
  </code></pre>
  
  <p>The problem with the first programme is that this error pops up: </p>
  
  <p>TypeError: list indices must be integers, not tuple</p>
  
  <p>I therefore attempted this method:</p>
  
  <pre><code>import csv
  
  searchfile = raw_input ('Which file do you want to search?   ')
  try:
      input_file = open (searchfile, 'rU')
  except:
      print "Invalid file. Please enter a correct file"
  
  
  with open(searchfile) as f:
      reader = csv.reader(f, delimiter="\t")
      d = list(reader)
  
  searchtype = raw_input ('Search on author or journal/conference or [Q = quit]')
  
  
  if searchtype == 'author':
      searchdataA = raw_input ("Input author name")
      if searchdataA in input_file:
          print line
  
  elif searchtype == 'journal' or 'conference' or 'journal/conference':
      searchdataJ = raw_input ("input journal/conference name")
      if searchdataJ in d:
          print line
  
  elif searchtype == 'Q':
      print "Program left"
  
  else:
      print "please choose either author or journal/conference"
  </code></pre>
  
  <p>This is unable to get beyond inputting the search parameters. </p>
  
  <p>Any help on where to go with either programme would be much appreciated, or if I'm completely on the wrong track then links to useful material would be great. </p>