Can't understand what python wants from me

Chris Rebert clp2 at rebertia.com
Thu Jan 29 23:25:54 CET 2009


On Thu, Jan 29, 2009 at 1:50 PM, Oleksiy Khilkevich
<grim at asu.ntu-kpi.kiev.ua> wrote:
> Hello, everyone,
> This may be a totally noob question, but since I am one, so here is it.
>
> I have the following code (not something much of):
> http://paste.debian.net/27204
> The current code runs well, but the problem is with input value:
> http://paste.debian.net/27205
> Аs you can see, the numbers are ok, but strings and characters cause "not
> defined" error.
>
> I've obviously missing something important, but tutorial says nothing about
> this.

You're using input(). You should be using raw_input(), at least until
everyone switches to Python 3.0 (which confusingly renames raw_input()
to input() because of the exact newbie confusion you're encountering).
raw_input() reads a string from stdin. input() call raw_input() and
then eval()-s the string, hence 'asd' gets interpreted as a variable,
which doesn't exist in your program, hence the error.

For further information, use help() on input and raw_input from the
interactive interpreter REPL.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list