title: Python - loop through a csv file row values
body: <p>I have a csv file like the following (test.csv) with two columns.</p>
  
  <pre><code>338,800
  338,550
  339,670
  340,600 
  327,500
  301,430
  299,350
  284,339
  284,338
  283,335
  283,330
  283,310
  282,310
  282,300
  282,300
  283,290
  </code></pre>
  
  <p>From column 1, I wanted to read current row and compare it with the value of the previous row. If it is <code>greater</code> OR <code>equal</code>, continue comparing and if the value of the current cell is <code>smaller</code> than the previous row - then i wanted to the value of the second column in the same row.</p>
  
  <p>Next I wanted to divided the <code>larger value</code> we got in column 1 by the value in the same cell of column two. Let me make it clear.  </p>
  
  <p>For example in the table given above: the smaller value we will get depending on my requirement from Column 1 is 327 (because 327 is smaller than the previous value 340) - and then we take 500 (which is the corresponding cell value on column 2). <strong>Finally we divide 340 by 500 and get the value 0.68</strong>. My <code>python</code> script should exit right after we print the value to the console.</p>
  
  <p>Currently, I am using the following script in bash, and it works fine</p>
  
  <pre><code>awk -F, '$1&lt;p &amp;&amp; $2!=0{ 
  val=$2/p    
  if(val&gt;=0.8 &amp;&amp; val&lt;=0.9)
      {
          print "A"
      }
  else if(val==0.7)
      {
          print "B"
      }
  else if(val&gt;=0.5 &amp;&amp; val &lt;0.7)
      {
          print "C" 
  
      }
  else if(val==0.5)
      {
          print "E"
      }
  else
      {
          print "D" 
      }
  exit
  }
  { 
      p=$1 
  }' test.csv
  </code></pre>
  
  <p>but I wanted to do it with <code>python</code> and i would appreciate for any help. Here is my approach</p>
  
  <pre><code>import csv
  
  f = open("test.csv", "r+")
  ff = csv.reader(f)
  
  previous_line = ff.next()
  while(True):
      try:
          current_line = ff.next()
          if previous_line &lt;= current_line:
              print "smaller value"
      except StopIteration:
          break
  </code></pre>