[Tutor] Redirecting output

Rick Owen rickowen@yahoo.com
Mon Jun 16 22:11:45 2003


Greetings,

I have a script that scans log files for error messages.  Normally it just
outputs the error messages to stdout with the print statement. I want to add
the option to specify an output file.  If an output file is specified then I
want to print to the output file otherwise I want to print to stdout.

What I don't want to do (unless I have to) is

if output:
   print >> f, error_message
else:
   print error_message

Is there a way to explicitly open sys.stdout so that it is assigned to f if no
output file is specified. That way I can always use

print >> f, error_message

where f would be either the output file or stdout.

Thanks,
Rick.

=====
French President Jacques Chirac met with President Bush in France Sunday. It is hard to exaggerate their mutual contempt. The last time two presidents were this angry at one another, only their daughter Chelsea could get them talking again.

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com