Hi David...
You need to explicitly name your form element to "inputkey" to make
your current code work correctly. ( Based on what you have shown
below.)
Or, to make the code correct, change "inputkey" to "language".
Remember that the name in each form element becomes the key in the
key/value pairs sent via POST or GET.
Patric
> I am trying to write a CGI program here is the code of
> the HTML
> <FORM ACTION="cgi-bin/party2.py" METHOD="POST">
> <P><SELECT NAME="language">
> <OPTION SELECTED>ALL
> <OPTION>Bromley
> <OPTION>Lewisham</OPTION>
>
> Here is the python
> #!/usr/bin/env python
>
> boroughdict = {
> 'BROMLEY': 0.5,
> 'LEWISHAM':0.1
> }
>
>
> class dummy: #mocked up input obj
> def __init__(self, str):
> self.value = str
>
> import cgi, string
> form = cgi.FieldStorage()
>
> def showboroughinfo(form):
> try:
> choice = form[inputkey].value
> except:
> choice = 'BROMLEY'
> print "not getting from form"
> choice = string.upper(choice)
> info = boroughdict[choice]
> #this is not being called
> newinfo = calcinfo(info)
> print "<H3></H3><P><PRE>"
> print cgi.escape (newinfo)
> print "</PRE></P><BR>"
> #print '<HR>'
>
> def calcinfo(info):
> #this is calcuate stuff
> info = str(info)
> return info
>
> print "Content-type: text/html\n"
> print "<TITLE>Languages</TITLE>"
> print "<H1>This will happen</H1><HR>"
>
>
> showboroughinfo(form)
> #print "Hi"
> print '<HR>'
>
> For some reason it is not get the info in the try
> block.
> If I do not have the try block I get this message :-
> Traceback (most recent call last):
> File
> "/home/david/Documents/pyprogramming/cgi-bin/party2.py",
> line 45, in ?
> showboroughinfo(form)
> File
> "/home/david/Documents/pyprogramming/cgi-bin/party2.py",
> line 19, in showboroughinfo
> choice = form[inputkey].value
> File "/usr/lib/python2.3/cgi.py", line 552, in
> __getitem__
> raise KeyError, key
> KeyError: 'borough'
>
>
> Why is the input key not working ?
> Thanks in advance.
>
>
>
>
>
> ___________________________________________________________
> ALL-NEW Yahoo! Messenger - all new features - even more fun!
> http://uk.messenger.yahoo.com
> _______________________________________________ Tutor maillist -
> [email protected] http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor