How to print a string one char at a time, with no spaces?

Daniel T. a at b.c
Fri Oct 18 09:09:17 EDT 2002


Richard Bow <donkan7 at yahoo.com> wrote:

>I'd like to write a script that appears to be calculating digits of pi and 
>spitting them out one at a time, with no spaces, such as below (pi to 1002 
>digits, gotten from http://www.angio.net/pi/piquery ). It's easy to do this 
>by 
>
>pi = str(pi)
>for k in range(len(pi)):
>   print pi[k],
>
>but this prints 3 . 1 4 1 5 9 2 6 5 ...
>
>How to print without those Python spaces (which are very nice when you want 
>them)?

This works:

from math import pi
from sys import stdout

spi = str(pi)
for k in spi:
   stdout.write( k )

But it only prints the first 13 characters...



More information about the Python-list mailing list