<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.6944.0">
<TITLE>Writing to a file...</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">I'm somewhat new to Python and this is my first question to the list.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">In the example below you can see that it takes four write statements to equal one print statement.</FONT>

<BR><FONT SIZE=2 FACE="Arial">At the moment I'm using print statements and redirecting them to a file when I run the script (foo.py &gt; outfile).</FONT>
</P>
<BR>

<P><FONT SIZE=2 FACE="Arial">Example using print:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">dimes = 3</FONT>

<BR><FONT SIZE=2 FACE="Arial">nickels = 5</FONT>

<BR><FONT SIZE=2 FACE="Arial">numofcoins = dimes + nickels</FONT>

<BR><FONT SIZE=2 FACE="Arial">money = dimes * 0.1 + nickels * 0.5</FONT>

<BR><FONT SIZE=2 FACE="Arial">print 'You have ', numofcoins, 'coins totaling $', money</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">&gt;&gt;&gt;You have 8 coins totaling $ 0.55</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">for the same line, write() is more cumbersome:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">outfile.write('You have ')</FONT>

<BR><FONT SIZE=2 FACE="Arial">outfile.write(numofcoins)</FONT>

<BR><FONT SIZE=2 FACE="Arial">outfile.write(' coins totaling $')</FONT>

<BR><FONT SIZE=2 FACE="Arial">outfile.write(money)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Is there a more efficient way of doing this, or some way I can redirect the output internally?</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">-Greg Bartz</FONT>
</P>
<BR>

</BODY>
</HTML>