Simple Problems: Caps and Commas
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Mon Oct 27 12:59:37 EST 2003
On 27 Oct 2003 09:06:05 GMT, rumours say that keflimarcusx at aol.comNOSPAM
(KefX) might have written:
>>I keep looking, but I don't see any "extra spaces".
>
>Then either you don't understand what I mean, or you're not looking hard
>enough.
Mu (which in this case it could mean, "The choices you offer aren't
sufficient to cover what happens here, because you are overlooking
something." :) Google for "jargon mu".
>print "this, ", "that, ", "and the other"
>
>The "extra spaces" are the spaces after each comma in the first two
>double-quoted strings. It prints out:
>this, that, and the other
>
>instead of:
>this, that, and the other
KefX,
the OP used the line:
>print "Address: ",saddy, ",",city, ",",state, ",",zip
This is what you are overlooking: the comma operator in the print
argument list inserts spaces between arguments, therefore also between
the variables and the literal commas (","). saddy, city and state don't
end in a space, and there is no space in ",".
The cryptic way to solve this is to fiddle with sys.stdout.softspace.
The /preferably obvious/ way is to use string interpolation, which is
definitely not overkill, if you do some benchmarking.
Cheers :)
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix
More information about the Python-list
mailing list