[Tutor] CGI-version not working while similar command-line
script is fine
Kent Johnson
kent_johnson at skillsoft.com
Fri Sep 3 18:17:52 CEST 2004
At 04:53 PM 9/3/2004 +0100, Gerhard Venter wrote:
>I suspect there is a hint in the fact that I had to use raw_input instead
>of just input for the cmd-line version (just input causes a
>NameError). Maybe the CGI-module has its own version of this effect
I don't know what is wrong with your CGI but this isn't it. When you just
want to input a string, raw_input() is the correct method. input()
_evaluates_ what you type, just as if you had typed it to the interpreter,
and returns the result. That's why you get a NameError
For example, using input() what I type is evaluated:
>>> while 1:
... print input("What? ")
...
What? 1
1
What? 1+2
3
What? str
<type 'str'>
What? foo
Traceback (most recent call last):
File "<stdin>", line 2, in ?
File "<string>", line 0, in ?
NameError: name 'foo' is not defined
The same thing with raw_input() just echoes back exactly what I type:
>>> while 1:
... print raw_input('What? ')
...
What? 1
1
What? 1+2
1+2
What? str
str
What? foo
foo
Kent
More information about the Tutor
mailing list