Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Simple print to stderr

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


raymond.chui at nospam

Oct 27, 2008, 11:29 AM

Post #1 of 2 (17037 views)
Permalink
Simple print to stderr

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.

--
http://mail.python.org/mailman/listinfo/python-list


mnordhoff at mattnordhoff

Oct 27, 2008, 11:41 AM

Post #2 of 2 (16901 views)
Permalink
Re: Simple print to stderr [In reply to]

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.
--
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.