Simple print to stderr

Matt Nordhoff mnordhoff at mattnordhoff.com
Mon Oct 27 14:41:38 EDT 2008


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.
-- 



More information about the Python-list mailing list