newbie question: getting rid of space in string :(

Alex Martelli aleax at aleax.it
Fri Jul 12 13:29:03 EDT 2002


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




More information about the Python-list mailing list