Comparison problem

Chris coz1978 at gmail.com
Sat Nov 26 14:02:40 EST 2005


Hi,

I'm new to python, and I'm trying to write a small python script for a
webpage.  The script opens up a file called inventory, reads the
contents, and checks the contents against the data from the form in my
webpage.  Now I have to do some slicing to get the name of the form
elements (in this case, checkboxes), to resemble the values in the
inventory file.  Here's my python part:

#!/usr/local/bin/python
import cgi
import types
from Cookie import *
form=cgi.FieldStorage()
user_answer=[]
error='false'
item=''
qty=''
def main():
  print"Content-type: text/html\n"
  i=open("inventory","r")
  keys=form.keys()
  for key in keys:
   field=form[key]
   if type(field)==types.InstanceType:
    item=field.value
    if item[0:1]=="-":
     item=item[ :-7]
     item=item[1:]
     infile=open("inventory","r")
     while infile:
      dummy=infile.readline()
      if dummy=='':break
      print item
      print ", "+dummy
      if (dummy == item): <This comparison isn't working>
       print"Found it"
      else:
       print"Didn\'t Find it"
      print "<br>"
     infile.close()
    else:
     #print"	Quantity: "
     #print item
     print"<br>"
    #print field.value
   else:
    print"BAD"
main()

Let me know if more information is needed.  Any assistance will be
greatly appreciated.




More information about the Python-list mailing list