|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Reading values from GET using cgi
HI.
I have a bbt of a problem and I would appreciated your help. Usually to read values, I use form = cgi.FieldStorage() and then treat the form variable like a dictionary type but.... how can you read the values if there are multiple keys, for example if we write in the HTML <select Name="lstRsrcs" SIZE='4' MULTIPLE> <option VALUE="Rsrc1">Rsrc1Desc</option> <option VALUE="Rsrc2">Rsrc2Desc</option> <option VALUE="Rsrc3">Rsrc3Desc</option> </select> and we select more then one option, the http will look something like: url ?lstRsrcs=Rsrc1&lstRsrcs=Rsrc2&lstRsrcs=Rsrc3 how can I read that?! or iterate through that? Thanks a lot Roy |
|
#2
|
|||
|
|||
|
If you are using version 2.2 or later you can use the getlist method. From the docs:
Quote:
For versions prior to 2.2, the FieldStorage.getvalue(name) method returns a string if there is only one item and a list if there is more than one, so you have to check explicitly. From the docs again: Code:
item = form.getvalue("item")
if isinstance(item, list):
# The user is requesting more than one item.
else:
# The user is requesting only one item.
Regards, Dave - The Developers' Coach |
|
#3
|
||||
|
||||
|
I recently had to write a form parser as part of my net module, as part of this it had to accomodate multiple fields with the same value. Anyway i've attached the file; as an example of parsing and use values from GET/QUERY_STRING.
Have fun, Mark. |
|
#4
|
|||
|
|||
|
Thanks Dave
Quote:
This is exactly what iv'e done and it works beautiful thank you for the very good explanation and examples Roy |
|
#5
|
|||
|
|||
|
Thanks Mark
Quote:
I solved the problem by using form.GetList method that Dave suggested. I will read your module throughly, and I'm sure that I can learn a lot from that. Thanks a lot Roy |
|
#6
|
||||
|
||||
|
No problem at all roypy, i didnt expect that you would be wrting you're own form parser to solve a simple problem like this but as an example of how a form parser might work it works very well
![]() Take care, Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Reading values from GET using cgi |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|