How to print a string one char at a time, with no spaces?
Eric Brunel
eric.brunel at pragmadev.com
Fri Oct 18 09:01:16 EDT 2002
Richard Bow 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)?
Use:
import sys
...
sys.stdout.write(pi[k])
and
sys.stdout.write('\n')
at the end. It should do what you want.
--
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list
mailing list