[Tutor] How to write this to a file?

Kent Johnson kent37 at tds.net
Fri Oct 7 00:43:45 CEST 2005



Hans Dushanthakumar wrote:
>  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.
> 
 
> TCL provides a more handy way of doing this:
> print $fptr "Hi there"

In Python you can say
print >>fptr, "Hi there"

Kent

> 
> Cheers
> Hans
> 
> 
> -----Original Message-----
> From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
> Behalf Of Dick Moores
> Sent: Thursday, 6 October 2005 12:18 p.m.
> To: tutor at python.org
> 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  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 



More information about the Tutor mailing list