title: Once again, how to get nested loops to work in python
body: <p>Can someone help me with this nested loop? it has the same problem as <a href="https://stackoverflow.com/questions/6383284/loops-not-working-strings-python/6383387#6383387">Loops not working - Strings (Python)</a> but now it is in a csv class that doesn't have a csv.readline() function. </p>
  
  <pre><code>import csv
  import sys, re
  import codecs
  reload(sys)
  sys.setdefaultencoding('utf-8')
  
  reader = csv.reader(open("reference.txt"), delimiter = "\t")
  reader2 = csv.reader(open("current.txt"), delimiter = "\t")
  
  for line in reader:
      for line2 in reader2:
          if line[0] == line2[1]:
              print line2[0] + '\t' + line[0]
              print line[1]
          else:
              print line[0]
              print line[1]
  </code></pre>
  
  <p>The purpose of this code is to check the lines in a reference text (i.e. reader2) that coincide with the current textfile (i.e. reader). And then print the serial number that is in the reference.txt</p>
  
  <p>reference.txt looks like this (the space between the serial no. and sentence is a <code>tab</code>):</p>
  
  <pre><code>S00001LP    this is a nested problem
  S00002LP    that cannot be solved
  S00003LP    and it's pissing me off
  S00004LP    badly
  </code></pre>
  
  <p>current.txt looks like this(the space between the 1st and 2nd sentence is a ):</p>
  
  <pre><code>this is a nested problem    wakaraa pii ney bay tam
  and i really can't solve it    shuu ipp faa luiip
  so i come to seek help from stackoverflow    lakjsd sdiiije
  seriously it is crazy because such    foo bar bar foo
  problems don't happen in other languages    whaloemver ahjd
  and it's pissing me off    gaga ooo mama
  badly    wahahahah
  </code></pre>
  
  <p>the required output will look something like this:</p>
  
  <pre><code>S00001LP    this is a nested problem    wakaraa pii ney bay tam
  and i really can't solve it    shuu ipp faa luiip
  so i come to seek help from stackoverflow    lakjsd sdiiije
  seriously it is crazy because such    foo bar bar foo
  problems don't happen in other languages    whaloemver ahjd
  S00003LP    and it's pissing me off    gaga ooo mama
  S00004LP    badly    wahahahah
  </code></pre>