[Tutor] Printing
Jeff Shannon
jeff@ccvcorp.com
Fri Feb 14 17:20:02 2003
Pete Versteegen wrote:
>Hi pythonians,
>
>I'm wrestling with a formatting issue:
>
>>>>x=['h','e','l','l','o']
>>>>for i in range(0, len(x)):
>>>>
>>>>
>... print x[i],
>...
>h e l l o
>
>
If you need more fine-grained control of output than you can get from
print, then use sys.stdout.write().
>>> import sys
>>> for x in ['h', 'e', 'l', 'l', 'o']:
... sys.stdout.write(x)
...
hello
>>>
Where print does a variety of convenient formatting tricks that make it
convenient for common usages, sys.stdout.write() provides raw access to
the normal output stream.
Jeff Shannon
Technician/Programmer
Credit International