473,769 Members | 6,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3000

"Helmut Jarausch" <ja************ *@igpm.rwth-aachen.de> wrote in message
news:bv******** **@nets3.rz.RWT H-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(promp t) 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.RWT H-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('plea se 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.RWT H-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('plea se 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******@skyne t.be> wrote in message
news:40******** ******@skynet.b e...
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.e du>:
[... 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.co m
Jul 18 '05 #6

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

Similar topics

4
7702
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 = function_xyz("GIVE ME AN ANSWER: ", time_limit) The problem with "raw_input" is that it will stop unattended script indefinitely. I'm looking for a function that does the exact same thing, but with a time limit feature, and preferably one that returns
16
5647
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
7241
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 if a player enters the 'shutdown' command, everything shuts down, but the input thread is still sitting waiting for enter to be pressed for raw_input. After enter is pressed, it exits back to the command prompt as it should. I'm wondering if...
21
8778
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 like to include the ability to edit an existing value (drawn from an SQLite table) using a DOS console Python app, but my gut
2
1490
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 raw_input prompt to continue or break. here's what I have: ########### def makegroepen(): global p
1
1873
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 value they can edit as they wish at the prompt: result = raw_input("Enter value: ") #### Somehow output default value so prompt looks like:
7
2047
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 prompt output from raw_input goes to stderr. Consider the following test program: === Start test.py === import sys
8
5318
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. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
5
7118
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
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.