Receing a form variable as a list instead of as a string

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jun 12 02:16:16 EDT 2013


On Tue, 11 Jun 2013 18:29:05 -0700, nagia.retsina wrote:

> if page or form.getvalue('show') == 'log':
>         # it is a python script
>         page = page.replace( '/home/nikos/public_html/cgi-bin', '' )
> elif page or form.getvalue('show') == 'stats':
>         page = page.replace( '/home/nikos/public_html/cgi-bin', '' )
> 
> 
> in the first if option page works a string and replace happens , while
> in the second it behaves liek a list and the error i mentioned is being
> produced.


It doesn't *behave* like a list. It **IS** a list. I know that people 
have already pointed you to the documentation, where getvalue is 
documented to return either a string or a list, depending on how many 
values there are in the form.

So, yet again, here is the documentation:

http://docs.python.org/3/library/cgi.html


READ IT.

Here is an extract:

[quote]
In the previous section, you learned to write following code anytime you 
expected a user to post more than one value under one name:

item = form.getvalue("item")
if isinstance(item, list):
    # The user is requesting more than one item.
else:
    # The user is requesting only one item.
[end quote]


Read the rest of the docs. Don't ask any more questions until you have 
read them. Then, if anything is still unclear, you can point to a section 
of the docs and say "I don't understand this".



-- 
Steven



More information about the Python-list mailing list