[New-bugs-announce] [issue1927] raw_input behavior incorrect if readline not enabled
report at bugs.python.org
Thu Jan 24 21:21:18 CET 2008
New submission from Skip Montanaro:
>From a thread on python-dev...
Mike Kent mike.kent at sage.com
Thu Jan 24 16:33:47 CET 2008
Recently I was trying to debug an old python program who's maintenance I
inherited. I was using the quick-and-dirty method of putting some 'print
>>sys.stderr' statements in the code, and then running the command with
'2>filename' appended to the end of the command line. Imagine my surprise
to see that all of the prompt text from the program's raw_input calls were
also disappearing from the screen output, and appearing in the stderr
output routed to the file.
The latest documentation for raw_input states "If the prompt argument is
present, it is written to standard output without a trailing newline."
I posted a question regarding the observed behavior to comp.lang.python
and Gabriel Genellina (thanks Gabriel!) pointed out that despite the
documentation, raw_input was hard-coded to always output its prompt text
This raises two questions:
1. Shouldn't the current documentation be corrected to state that raw_input
writes its prompt to standard error?
2. Is this really the hard-coded behavior we want? I don't think my
use-case is that odd; in fact, what I find very odd is that the prompt
output is send to stderr. I mean, I'm printing the prompt for a question,
not some error message. Can there not at least be an optional parameter to
indicate that you want the output sent to stdout rather than stderr?
... after a few responses ...
Guido van Rossum guido at python.org
Thu Jan 24 21:09:12 CET 2008
On Jan 24, 2008 11:41 AM, Mike Kent <mike.kent at sage.com> wrote:
> Interesting point about whether GNU readline is installed. My setup
> Linux, with Python 2.5 that I built and installed myself. GNU
readline is not,
> in fact, installed. If you look at Python2.5/Parser/myreadline.c,
> PyOS_StdioReadline, line 125, you will see that prompt output is being
> stderr. As best as my Python-fu can determine, this is the code used
> a raw_input prompt (thanks again to Gabriel Genellina for pointing me
> right direction.)
> It's entirely likely that the difference in what I am seeing and what
> are seeing is caused by my not having GNU readline installed.
> the behavior without it seems wrong, and is certainly different from the
components: Interpreter Core
title: raw_input behavior incorrect if readline not enabled
versions: Python 2.5, Python 2.6
Tracker <report at bugs.python.org>
More information about the New-bugs-announce