Multiple Select

Ethan Furman ethan at stoneleaf.us
Fri Oct 2 18:22:57 EDT 2009


Victor Subervi wrote:
> I have the select called variable "these". Whichever option is selected 
> is passed through the cgi:
> 
> import cgitb; cgitb.enable()
> import cgi
> 
> form = cgi.FieldStorage()
> these = form.getfirst('these', '')
> 
> As I mentioned before, I get the variable all right. That is not the 
> issue. What is the issue is that I would like to enable the user to 
> select *several* options; in essence, to turn "these" into a tuple. That 
> way, I could capture *several* options and enter them all into my 
> database at once.
> TIA,
> V
> 

Please don't top post.

 From the docs:

getfirst( name[, default])

This method always *returns* *only* *one* value associated with form 
field name. The method returns only the first value in case that more 
values were posted under such name. Please note that the order in which 
the values are received may vary from browser to browser and should not 
be counted on.18.1 If no such form field or value exists then the method 
returns the value specified by the optional parameter default. This 
parameter defaults to None if not specified.

getlist( name)

This method always *returns* *a* *list* of values associated with form 
field name. The method returns an empty list if no such form field or 
value exists for name. It returns a list consisting of one item if only 
one such value exists.


Hope this helps.

~Ethan~



More information about the Python-list mailing list