| Store | Cart

newbie question: getting rid of space in string :(

From: Alex Martelli <ale...@aleax.it>
Fri, 12 Jul 2002 17:29:03 GMT
Joseph Youssef wrote:
        ...
>         print "<" +color+ "><b>" +a+ "</b></" +color+ ">",
        ...
> now this works just fine exept that space in between each block of text, I

print's job is to put that space there.  Don't want the space, don't
use print -- use sys.stdout.write instead:

    sys.stdout.write("<" +color+ "><b>" +a+ "</b></" +color+ ">")

voila, no space -- nothing but what you pass as write's argument.

Personally I'd prefer to use % formatting here:

    sys.stdout.write("<%s><b>%s</b></%s>" % (color, a, color) )

I find it more readable -- but that's another issue.


Alex

Recent Messages in this Thread
Joseph Youssef Jul 12, 2002 05:52 am
Mark McEahern Jul 12, 2002 04:14 pm
Gerhard Haering Jul 12, 2002 04:17 pm
Martin Franklin Jul 12, 2002 04:59 pm
Alex Martelli Jul 12, 2002 05:29 pm
Alex Martelli Jul 12, 2002 05:30 pm
Martin Franklin Jul 12, 2002 06:49 pm
Messages in this thread