more print statemente without spaces

Peter Hansen peter at engcorp.com
Thu Feb 6 13:42:32 EST 2003


Federico wrote:
> 
> I'd like to have more print statements like these:
> print "a",
> ...
> ..
> print "b",
> ..
> ..
> print "c",
> -------
> to have "abc"
> but I have "a b c " .
> How can I have "abc" without spaces?

import sys
sys.stdout.write('a')
sys.stdout.write('b')
sys.stdout.write('c')

Don't use print if you don't want the benefits of its convenience
features.  It is not the only way to get output, just a way of 
getting minimally formatted output when you don't particularly
care about the details.  If you care a lot, use sys.stdout.write()
and you have full control.

-Peter




More information about the Python-list mailing list