title: Python form handling
body: <p>Could anyone help me find the problem in my Python script? This script simply gets a request posted from an HTML form with a few radio buttons.</p>
  
  <pre><code>import cgi
  from file import *
  form = cgi.FieldStorage()
  
  print "Content-type: text/html"
  print
  print """&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;"""
  
  print "&lt;html&gt;"
  print "&lt;head&gt;"
  print "&lt;meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"&gt;"
  print "&lt;title&gt;&lt;/title&gt;"
  print "&lt;/head&gt;"
  print "&lt;body&gt;"
  
  choice = form.getvalue('option')
  
  f = File("onlineVotes.txt")
  
  if choice is None:
      print "&lt;p class='error'&gt;Please choose an option before voting.&lt;/p&gt;"
      print "&lt;br&gt;&lt;a href='onlinePoll.html' class='backVoteAgain'&gt;Go back&lt;/a&gt;"
  
  else:
      if f.exists() == False:
          f.startWrite()
          f.write(choice)
          print choice
          print "&lt;div class='voteBar' style='width: 250px;'&gt;"
          print 1
          print "&lt;/div&gt;"
  
      else:
          f.startRead()
          choice = f.read() + " " + choice
          choiceList = choice.split()
  
          filterList = []
  
          for item in choiceList:
              if item not in filterList:
                  filterList.append(item)
  
          choiceDict = {}
  
          for elem in filterList:
              print "&lt;br&gt;" + elem
  
              counts = choiceList.count(elem)
  
              choiceDict['%s' % elem] = counts
              maxValue = max(choiceDict.values())
  
              barWidth = counts*250/maxValue
  
              print "&lt;div class='voteBar' style='width: %spx;'&gt;" % str(barWidth)
              print counts
              print maxValue
              print "&lt;/div&gt;"
  
          totalVotes = str(sum(choiceDict.values()))
          print "&lt;br&gt;Total number of votes: " + totalVotes
  
      f.startWrite()
      f.write(choice)
      f.close()
  
  print "&lt;/body&gt;"
  print "&lt;/html&gt;"
  </code></pre>
  
  <p>The problem with this is that when option1 gets 10 votes, option2 gets 5 votes and option3 gets 3 votes, the value of max(choiceDict.values()) is 10, which is good as expected. However, when option1 gets 10 votes, option2 gets 11 votes and option3 gets 5 votes, the max value for option1 stays at 10 while it is 11 for both option2 and option3.</p>
  
  <p>Where did I do wrong?</p>