473,396 Members | 1,722 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,396 software developers and data experts.

Simple print to stderr

RC
By default the print statement sends to stdout
I want to send to stderr

Try

print "my meeage", file=sys.stderr

I got
SyntaxError: invalid syntax
I try

print "my message", sys.stderr

But it still sent to stdout.
What is the syntax?

I wouldn't understand Python's manual

print([object, ...][, sep=' '][, end='n'][, file=sys.stdout])¶

Print object(s) to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no object is given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used.
Oct 27 '08 #1
1 4215
RC wrote:
By default the print statement sends to stdout
I want to send to stderr

Try

print "my meeage", file=sys.stderr

I got
>SyntaxError: invalid syntax

I try

print "my message", sys.stderr

But it still sent to stdout.
What is the syntax?

I wouldn't understand Python's manual
<snip quote from the manual>

That's only in Python 3 (or 2.6 with the proper __future__ import).
Before that, print is a statement. You'd do it like this:

print >sys.stderr, "whatever"

You should look at
<http://docs.python.org/reference/simple_stmts.html#the-print-statement>,
not Python 3's documentation.
--
Oct 27 '08 #2

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

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
1
by: Manfred Schwab | last post by:
Recording messages and print statements in a textfile during program execution. Is there a similar command to redirect errormessages or print statements into a standart asciifile during...
21
by: Advocated | last post by:
Just been searching google, but havent come up with anything. Just wondering, whats the best way to print say a file.txt or other format to the screen? A link would be great and ill read up on it....
10
by: Brennan Young | last post by:
Hi there, First I'll apologise for my ignorance! I have been attempting to compile some code that I found on the net. AFAICT it's intended to be portable code (it was available as source and...
11
by: A.M | last post by:
Hi, I found print much more flexible that write method. Can I use print instead of file.write method? Thank you,
16
by: saurabhnsit2001 | last post by:
The following program doesn't "seem" to print "hello-out". (Try executing it) #include <stdio.h> #include <unistd.h> int main() { while(1) { fprintf(stdout,"hello-out");
9
by: cniharral | last post by:
Hi, I'm interested in printing out coloured lines of my application and I don't know what to use. Can anybody give me an idea?? Regards. Carlos Niharra López
5
by: sakismat | last post by:
please help how can I get stderr from processes ($proc) in my screen without waiting the other processes to end #!/usr/bin/php <?php $con = mysql_connect("localhost", "user"); if (!$con)
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.