printing without spaces

Richard Jones richard at bizarsoftware.com.au
Mon Nov 19 17:20:59 EST 2001


On Tuesday 20 November 2001 09:08, David Brady wrote:
> Hello,
>
> I'm trying to print a list of information
> programmatically.   Using 'print i,' doesn't quite
> work the way I'd like because the , seems to inject a
> space between arguments.
>
> Is there a way to do this with print?
>
> Thanks
>
> Here's a sample of what I'm talking about:
> >>> for i in range(3):
>
> 	for j in range(10):
> 		print "%d%d" % (i,j),
> 	print
>
>
> 00 01 02 03 04 05 06 07 08 09
> 10 11 12 13 14 15 16 17 18 19
> 20 21 22 23 24 25 26 27 28 29
>
> I'd like the output to be
>
> 00010203040506070809
> 10111213141516171819
> 20212223242526272829

print is a convenience statement. You need to use the sys.stdout file 
directly to control writing in this way.

>>> import sys
>>> for i in range(3):
...  for j in range(10):
...   sys.stdout.write("%d%d"%(i, j))
...  print
... 
00010203040506070809
10111213141516171819
20212223242526272829



     Richard




More information about the Python-list mailing list