Helpful Information
 
 
Category: Python Programming
do i need to define something that a value is already defined to?

I have a cgi and i have managed to get the radio buttons working, and can print their value. Eg the button is searchtype and it's value could be substructure.
So when I write:
print searchtype
substructure is printed.

However if I type:
if searchtype == substructure:
Print "the search is substructure"

I get an error saying that substructure is not defined, how do I get around this does anyone know?

Cheers,

NiCkNaMe

Do this instead:



if searchtype == "substructure":
print "the search is substructure"


If you don't have quotes around "substructure," Python thinks that it is a variable name and tries to look up the value of it to compare with the value of searchtype. As there is no variable "substructure" defined, you get an error. Putting quotes around it makes it a string literal.










privacy (GDPR)