What happens to the variable outside of the for loop in this piece of code?
<p>I apologize for the lack of clarity in my question, and trying to elucidate:</p>

<p>When I print values of a for loop:</p>

<pre><code>  for uniqueValue in dValues:
    print uniqueValue
</code></pre>

<p>This works as expected.</p>

<p>However, when I do the following:</p>

<pre><code>  for uniqueValue in dValues:
    counter+=1
    theHash=hashlib.sha224(uniqueValue).hexdigest()
    for row in inputFileText:
      if counter&gt;1:
        print row[DISTINCTCOLUMN] + '     ' + uniqueValue + str(counter)
</code></pre>

<p>This for some reason will NEVER enter the <code>IF</code> statement. </p>

<p>I know without a doubt that there are multiple values in <code>dValues.</code></p>

<p>I would be most grateful for any guidance on this issue. </p>

<p>here is the full source:</p>

<pre><code>import hashlib
import csv

def doStuff():
  createFiles('together.csv')

def readFile(fileName):
  a=open(fileName)
  fileContents=a.read()
  a.close()
  return fileContents

def readCSVFile(fileName):
  return csv.reader(open(fileName, 'rb'), delimiter=',', quotechar='"')

def GetDistinctValues(theFile, theColumn):
    with open(theFile, "rb") as fp:
        reader = csv.reader(fp)
        return set(line[theColumn] for line in reader)

def createFiles(inputFile):
  cNAME=3
  clat=0
  clongitude=1
  caddress1=4
  caddress2=5
  cplace=6
  ccity=7
  cstate=8
  czip=9
  cphone=10
  cwebsite=11
  cstyleID=18
  inputFileText=readCSVFile(inputFile)
  headerFile = readFile('header.txt')
  footerFile = readFile('footer.txt')
  r=headerFile
  DISTINCTCOLUMN=12
  dValues = list(GetDistinctValues(inputFile,DISTINCTCOLUMN))
  counter=0

  for uniqueValue in dValues:
    counter+=1
    theHash=hashlib.sha224(uniqueValue).hexdigest()
    for row in inputFileText:
      if counter&gt;1:
        print row[DISTINCTCOLUMN] + '     ' + uniqueValue + str(counter)
      if uniqueValue==row[DISTINCTCOLUMN]:
        for eachElement in row:
          eachElement=eachElement.replace('&amp;','&amp;amp;')            
        desc = ' '.join(row[3:])
        r += '\n&lt;Placemark&gt;&lt;name&gt;'+row[3].encode('utf-8','xmlcharrefreplace')+'&lt;/name&gt;' \
             '\n&lt;description&gt;'+desc.encode('utf-8','xmlcharrefreplace')+'&lt;/description&gt;\n' \
             '&lt;Point&gt;&lt;coordinates&gt;'+row[clat]+','+row[clongitude]+'&lt;/coordinates&gt;&lt;/Point&gt;\n' \
             '&lt;address&gt;'+row[4]+'&lt;/address&gt;\n' \
             '&lt;styleUrl&gt;'+'#'+row[cstyleID]+'&lt;/styleUrl&gt;\n' \
             '&lt;/Placemark&gt;'        
    r += footerFile
    f = open(theHash+'.kml','w')
    f.write(r)
    f.close()
    r=headerFile
</code></pre>
