473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

raw_input - why doesn't prompt go to stderr

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
Jul 18 '05 #1
5 2981

"Helmut Jarausch" <ja*************@igpm.rwth-aachen.de> wrote in message
news:bv**********@nets3.rz.RWTH-Aachen.DE...
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


Jul 18 '05 #2
Terry Reedy wrote:
"Helmut Jarausch" <ja*************@igpm.rwth-aachen.de> wrote in message
news:bv**********@nets3.rz.RWTH-Aachen.DE...

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.


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
Jul 18 '05 #3
Terry Reedy wrote:
"Helmut Jarausch" <ja*************@igpm.rwth-aachen.de> wrote in message
news:bv**********@nets3.rz.RWTH-Aachen.DE...

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.


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

Jul 18 '05 #4

"Helmut Jarausch" <ja******@skynet.be> wrote in message
news:40**************@skynet.be...
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


Jul 18 '05 #5
Quoth "Terry Reedy" <tj*****@udel.edu>:
[... 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, do**@drizzle.com
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Radioactive Man | last post by:
anyone know of a function like "raw_input", which collects a string from the user entry, but one where I can set a time limit, as follows: time_limit = 10 # seconds user_answer =...
16
by: BOOGIEMAN | last post by:
I need something like "Press any key to continue" code for my program. Currently I use : raw_input("Press Enter to continue ") but it's lame.
2
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
2
by: tim | last post by:
I want to write a program that looks into a given folder, groups files that have a certain part of the filename in common and then copy those groups one at a time to another place, using the...
1
by: David Hirschfield | last post by:
Does the raw_input built-in function allow giving an initial value that the user can edit? Perhaps by using the readline module? I want to do something so that I can provide the user a default...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
5
by: jamitwidme | last post by:
Is there any way to type into a Tkinter frame window? I want to use raw_input() within a Tkinter frame.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.