raw_input - why doesn't prompt go to stderr

H

Helmut Jarausch

Hi

when using an interactive Python script, I'd like the prompt given by
raw_input to go to stderr since stdout is redirected to a file.

How can I change this (and suggest making this the default behaviour)

Many thanks for a hint,

Helmut Jarausch
RWTH Aachen University
Germany
 
T

Terry Reedy

when using an interactive Python script, I'd like the prompt given by
raw_input to go to stderr since stdout is redirected to a file.

This is not the usual behavior, so I presume that you or the code author
(if not the same) have done some non-standard redirection.
How can I change this

If you wrote or have access to the code, write your own (two-line?) version
of raw_input(prompt) using stderror.write(prompt) and return stdin.read().

Or leave stdout alone and use print >> ofile or ofile.write() for the other
stuff. Ofile can easily be selectable as either stdout or something else.

If you don't have the source, make suggestions to the owner/author.
(and suggest making this the default behaviour)

You just did, but part of the definition of 'interactive' is stdout to the
screen or other humanly immediately readable output device ;-)

Terry J. Reedy
 
H

Helmut Jarausch

Terry said:
This is not the usual behavior, so I presume that you or the code author
(if not the same) have done some non-standard redirection.

Ofcourse I did the redirection of stdout.
And here is an example which I give in my C++ courses when I tell the
students to use 'cerr' for outputting a prompt (in Python)

FileName= raw_input('please enter the name of data file')
input= open(FileName,'r')
....
print tons of output

And this is very handy.
While testing I don't redirect stdout and so can see the output
immediately. Then I just redirect stdout for a 'production' run.

Tell me any advantage in raw_input's prompt is going to stdout instead
of stderr?

Thanks for your comments,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
H

Helmut Jarausch

Terry said:
This is not the usual behavior, so I presume that you or the code author
(if not the same) have done some non-standard redirection.

Ofcourse I did the redirection of stdout.
And here is an example which I give in my C++ courses when I tell the
students to use 'cerr' for outputting a prompt (in Python)

FileName= raw_input('please enter the name of data file')
input= open(FileName,'r')
....
print tons of output

And this is very handy.
While testing I don't redirect stdout and so can see the output
immediately. Then I just redirect stdout for a 'production' run.

Tell me any advantage in raw_input's prompt is going to stdout instead
of stderr?

Thanks for your comments,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
T

Terry Reedy

Helmut Jarausch said:
Ofcourse I did the redirection of stdout.

Since a program author can easily do so, as has been posted more than once
over the years, the question was real. In fact, the addition of '>>ofile'
to print statements was intended to make such redirection less common.
And this is very handy.
While testing I don't redirect stdout and so can see the output
immediately. Then I just redirect stdout for a 'production' run.

Tell me any advantage in raw_input's prompt is going to stdout instead
of stderr?

I don't know the ramification of the distinction, expecially across
platforms, well enough to answer. I can only reiterate my suggestion,
given Python as it is today and will remain for some time, that you print
to 'ofile' with default ofile == sys.stdout but with command line or
interactive redirection.

Terry J. Reedy
 
D

Donn Cave

Quoth "Terry Reedy" <[email protected]>:
[... in response to]
|> Tell me any advantage in raw_input's prompt is going to stdout instead
|> of stderr?
|
| I don't know the ramification of the distinction, expecially across
| platforms, well enough to answer. I can only reiterate my suggestion,
| given Python as it is today and will remain for some time, that you print
| to 'ofile' with default ofile == sys.stdout but with command line or
| interactive redirection.

I don't know either, but agree that the cross platform point is
probably an issue. If it were strictly a UNIX application, I would
indeed expect prompt on stderr - as well as a lot of other stuff
that now goes to stdout. But I've heard complaints from the Windows
crowd that stderr output is a nuisance there in some way, and for
sure you couldn't expect MS to appreciate the virtue of this
distinction even if they do somehow observe it.

Donn Cave, (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top