[Tutor] One character output

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 14 Aug 2002 16:14:13 -0700 (PDT)


On Wed, 14 Aug 2002, John Ziriax wrote:

> I want to print out one character at a time without any return.
>
> print "x",
>
> prints the character X, but adds a space afterwards.
>
> How do I stop the space and print just the single character?

Hi John,

For really fine-grained control over standard output, you can use the
write() method in the 'sys.stdout' object:

###
>>> import sys
>>> def test():
...     sys.stdout.write("hello")
...     sys.stdout.write("world")
...
>>> test()
helloworld>>>
###

sys.stdout.write() will write exactly what you send to it, without
inserting spaces or newlines.


If you have more questions, please feel free to ask on Tutor.