Can someone explain this unexpected raw_input behavior?
BJörn Lindqvist
bjourne at gmail.com
Thu Jan 24 13:33:13 EST 2008
On Jan 24, 2008 8:08 AM, Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
> En Thu, 24 Jan 2008 01:00:53 -0200, Mike Kent <mrmakent at cox.net> escribió:
>
> > Gabriel, thank you for clarifying the source of this behavior. Still,
> > I'm surprised it would be hard-coded into Python. Consider an
> > interactive program, that asks the user several questions, and
> > displays paragraphs of information based on those questions. The
> > paragraphs are output using print, and the questions are asked via
> > raw_input. You want to do some simple debugging of the program by
> > printing some debugging statements via 'print >>sys.stderr', and you
> > don't want the debug output mixed in with the normal output on the
> > screen, so you try to route the debugging output to a file by adding
> > '2>filename' to the end of the command line.
> >
> > Unfortunately, you will no longer see any of the questions being
> > printed via raw_input. The rest of the output will be fine, but the
> > questions disappear. Your program just stops, without asking
> > anything... you have to guess what should be there.
>
> You have one console, two streams to output data (stdout and stderr), and
> three data sources (program output, user prompt, and debugging messages).
> Someone has to give.
> I'm now convinced that the current behavior is rather reasonable...
If it weren't for the documentation...
"If the prompt argument is present, it is written to *standard output*
without a trailing newline."
--
mvh Björn
More information about the Python-list
mailing list