[Tutor] Printing to Screen
Bob Gailer
bgailer@alum.rpi.edu
Wed Jul 30 16:53:01 2003
--=======3E5A30B5=======
Content-Type: multipart/alternative; x-avg-checked=avg-ok-6B4038B; boundary="=====================_20337353==.ALT"
--=====================_20337353==.ALT
Content-Type: text/plain; x-avg-checked=avg-ok-6B4038B; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
At 03:18 PM 7/30/2003 -0500, DORSEY_EDMUND_K@LILLY.COM wrote:
>Is there a way to print but not have it do a new line
>For instance in java you have print and println in C you have to specify
>the end of line marker.
>Whenever I use print in python is puts a newline.
>Do I need to use a different method for printing to the screen?
>For example...
>
>for x in xrange(0, 5):
> print x
>
>would print
>
>0
>1
>2
>3
>4
>
>What if I want it to print
>
>01234
I spoke too soon.
import sys
for x in xrange(0, 5):
sys.stdout.write(str(x))
sys.stdout.write('\n') # newline
Bob Gailer
bgailer@alum.rpi.edu
303 442 2625
--=====================_20337353==.ALT
Content-Type: text/html; x-avg-checked=avg-ok-6B4038B; charset=us-ascii
Content-Transfer-Encoding: 8bit
<html>
<body>
At 03:18 PM 7/30/2003 -0500, DORSEY_EDMUND_K@LILLY.COM wrote:<br><br>
<blockquote type=cite class=cite cite><font size=2>Is there a way to
print but not have it do a new line</font> <br>
<font size=2>For instance in java you have print and println in C you
have to specify the end of line marker.</font> <br>
<font size=2>Whenever I use print in python is puts a newline.
</font><br>
<font size=2>Do I need to use a different method for printing to the
screen? </font><br>
<font size=2>For example...</font> <br><br>
<font size=2>for x in xrange(0, 5):</font> <br>
<font size=2> print x</font>
<br><br>
<font size=2>would print</font> <br><br>
<font size=2>0</font> <br>
<font size=2>1</font> <br>
<font size=2>2</font> <br>
<font size=2>3</font> <br>
<font size=2>4</font> <br><br>
<font size=2>What if I want it to print </font><br><br>
<font size=2>01234</font> </blockquote><br>
I spoke too soon.<br>
import sys<br>
<font size=2>for x in xrange(0, 5):</font> <br>
sys.stdout.write(str(x))<br>
sys.stdout.write('\n') # newline<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
bgailer@alum.rpi.edu<br>
303 442 2625<br>
</body>
</html>
--=====================_20337353==.ALT--
--=======3E5A30B5=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-6B4038B
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003
--=======3E5A30B5=======--