[Tutor] Why does print add spaces ?

Don Arnold Don Arnold" <darnold02@sprynet.com
Sat Mar 15 19:08:01 2003


----- Original Message -----
From: "Tony Cappellini" <tony@tcapp.com>
To: <tutor@python.org>
Sent: Saturday, March 15, 2003 3:48 PM
Subject: [Tutor] Why does print add spaces ?


>
>
> In this example
>
>
> mystr="abcdefghi"
>
> for x in range(1,len(mystr)):
>     print "%s," % mystr[x],
>
>
> a, b, c, d, e, f, g, h, i,
>
> why does print add an implied space ??

I can't really answer as to the 'why', since it seems like a language design
issue. Like it or not, that's how the print command behaves.

> How would i change this if I didn't want any spaces between each printed
> character ?
>

You can write directly to stdout:

>>> import sys
>>> for a in 'this is a test':
 sys.stdout.write(a)

this is a test


HTH,
Don