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.FieldS torage()
user_answer=[]
error='false'
item=''
qty=''
def main():
print"Content-type: text/html\n"
i=open("invento ry","r")
keys=form.keys( )
for key in keys:
field=form[key]
if type(field)==ty pes.InstanceTyp e:
item=field.valu e
if item[0:1]=="-":
item=item[ :-7]
item=item[1:]
infile=open("in ventory","r")
while infile:
dummy=infile.re adline()
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.
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.FieldS torage()
user_answer=[]
error='false'
item=''
qty=''
def main():
print"Content-type: text/html\n"
i=open("invento ry","r")
keys=form.keys( )
for key in keys:
field=form[key]
if type(field)==ty pes.InstanceTyp e:
item=field.valu e
if item[0:1]=="-":
item=item[ :-7]
item=item[1:]
infile=open("in ventory","r")
while infile:
dummy=infile.re adline()
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.
Comment