title: Do something if first line of infile != something, if it is; continue
body: <p>I am reading a bunch of files, I want the program to check if the first line in the file is equal to something spesific, if it is, I want to continue loading the rest of the lines, if not, append some standard string to signal that I have no data.</p>
  
  <pre><code>inputlines = []
  try:
      #This is just to check if the file exists
      infile = open('snip...', 'r')
  except IOError:
      print "NODATA"
      return 0
  
  for line in infile:
      if not(&lt;first line in the file&gt; == &lt;something&gt;):
          inputlines.append("NODATA")
          return 0
      inputlines.append(line)
  </code></pre>
  
  <p>Is this doable in some smart built in way in python, or do I need to drop every line into inputlines, and then search inputlines to see if the first element is what I want it to be? Because that seems like a lot of extra work if I had say 10 000 files.</p>
  
  <p>I guess the TL;DR question is; Is there some way to identify the first line in an infile?</p>