Message61652
From a thread on python-dev...
http://mail.python.org/pipermail/python-dev/2008-January/076446.html
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
to stderr.
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
is RedHat
> 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,
function
> PyOS_StdioReadline, line 125, you will see that prompt output is being
sent to
> stderr. As best as my Python-fu can determine, this is the code used
to output
> a raw_input prompt (thanks again to Gabriel Genellina for pointing me
in the
> right direction.)
>
> It's entirely likely that the difference in what I am seeing and what
you guys
> are seeing is caused by my not having GNU readline installed.
Nevertheless,
> the behavior without it seems wrong, and is certainly different from the
> documentation.
Agreed. |
|
Date |
User |
Action |
Args |
2008-01-24 20:21:19 | skip.montanaro | set | spambayes_score: 0.00413485 -> 0.0041348543 recipients:
+ skip.montanaro |
2008-01-24 20:21:18 | skip.montanaro | set | spambayes_score: 0.00413485 -> 0.00413485 messageid: <1201206078.95.0.997961854688.issue1927@psf.upfronthosting.co.za> |
2008-01-24 20:21:17 | skip.montanaro | link | issue1927 messages |
2008-01-24 20:21:15 | skip.montanaro | create | |
|