Puzzling input problem

Chris Gonnerman chris.gonnerman at usa.net
Thu Mar 22 05:02:38 CET 2001

----- Original Message -----
From: "Stephen R. Figgins" <fig at monitor.net>
Subject: Puzzling input problem

> I ran into a puzzling problem combining print with raw_input().
> Normally I would pass the prompt string to raw_input, but instead I
> tried something like this:
>   print "prompt string: ",
>   answer = raw_input()
>   print answer
> When it prints answer, it is indented one space.  Why is raw_input()
> putting a space in there?  Is it a bug, a feature, an unintended side
> effect?  input() does this too.   I am currently using Active Python 2.0
> build 202.

Actually, raw_input isn't the culprit, exactly.  The print statement's
handler doesn't know that raw_input() has modified the screen contents, so
still behaves like the cursor is just after the "prompt string: " on the
inserting a space as the ref guide says it will.

Do it this way instead:

    answer = raw_input("prompt string: ")
    print answer

and you should get what you want.

More information about the Python-list mailing list