print outputs the string to the std output (sys.stdout). You could
redirect the std output to a file instead of the screen as follows, but
it's a bit clumsy.
fptr = open("hans.log", "a+")
import sys
sys.stdout = fptr
print "Hi there"
This will output the string into the file hans.log. However, to get it
to print to the screen again, u will need to have stored the original
contents of sys.stdout somewhere and then redirected sys.stdout to that
again.
TCL provides a more handy way of doing this:
print $fptr "Hi there"
Cheers
Hans
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Dick Moores
Sent: Thursday, 6 October 2005 12:18 p.m.
To: [email protected]
Subject: [Tutor] How to write this to a file?
I have a script that writes it's output to a file. I also print the time
with
print "Time was %.4g seconds" % (timeEnd - timeStart)
How could I also have the same output of the print expression, written
to the file?
Thanks,
Dick Moores
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor