title: Python, nested for loop
body: <p>I’m new to python and I’m having difficulties implementing a nested ‘for loop’. This might be simple but the following sample code which I tried doesn’t give me the intended result.  My task actually is to read the records from an attribute table (ArcGIS feature data) and compare it with every record in a CSV file. But initially I’m trying to do the same on with 2 CSV files and then apply the similar logic to my original problem. I’m trying to figure out the working of the loop and I can add the conditions of comparison later on. Any help is greatly appreciated. Thanks.</p>
  
  <p>The idea is that first row in file 1(CSV) compares itself to all the rows (row by row) in file 2(CSV), and then second row in file 1 does the same until each row of file 1 compares itself to all the rows in file 2. So in the anticipated outcome, I’m trying to see if for every row in file 1, if each row in file2 is considered.</p>
  
  <p>Example:</p>
  
  <pre><code>**File 1   File 2**
  ALPHA      All
  BETA       Bell
  GAMMA      Cell
  DELTA      Dell
  ITA 
  </code></pre>
  
  <p>Sample code:</p>
  
  <pre><code>import csv, sys, os, string 
  table1 = os.path.join(path, 'table1.csv')
  table2 = os.path.join(path, 'table2.csv')
  file1 = csv.reader(open(table1, 'r'))
  file2 = csv.reader(open(table2, 'r'))
  for row in file1:
      print row
      for prow in file2:
          print prow
  </code></pre>
  
  <p>Anticipated outcome:</p>
  
  <pre><code>   ALPHA
      All
      Bell
      Cell
      Dell
  
      BETA
      All 
      …..
  
      ITA
  
  All
  ..
  Dell
  </code></pre>