Simple Problems: Caps and Commas

Bjorn Pettersen bjorn.pettersen at comcast.net
Mon Oct 27 03:23:48 EST 2003


keflimarcusx at aol.comNOSPAM (KefX) wrote in
news:20031027025433.27723.00000133 at mb-m04.aol.com: 

>># the % operator does 'string interpolation' and gives you more
>>control # over the outputstring
>>print 'Name: %s, %s, %s' % (fname, mname, lname)
> 
> This is just overkill.

Actually, it's just plain wrong (sorry). Something similar on the print of 
the address would be correct (below)...

> No "string interpolation" is needed here, just
> the programmer inserted extra spaces and didn't expect the print
> statement to print spaces AFTER the spaces, like:
> print 'a ', 'b'  # prints a  b
> 
> as opposed to:
> print 'a', 'b'  # prints a b
> 
> Don't do things like string interpolation when they're not needed. It
> just makes the code less clear.

I disagree. I prefer more control than print over anything that escapes to 
the user... in addition I think

  print 'Address: %s, %s, %s, %s' % (sadd, city, state, zip)

is clearer than the comma saturated

  print "Address:",saddy,",",city,",",state,",",zip

but that might just be me ;-)

-- bjorn




More information about the Python-list mailing list