[FRPythoneers] Question about string.join method

jafo at tummy.com jafo at tummy.com
Mon Apr 30 16:30:18 MDT 2001

On Mon, Apr 30, 2001 at 04:24:55PM -0600, J. Wayde Allen wrote:
>OK I see that now.  Wouldn't have thought about the 
>    res = '%s%s' % (field[2], field[3] )
>one though.  Is there any particular advantage to one of these methods
>over any other?

Whichever makes the most sense.  Usually, string.join is used where you
have a large (possibly variable) list of things to deal with, and the '%s'
format strings are used where you have a smaller fixed set.  The really
cool one is the dictionary ones:

   data = { 'name' : 'Sean', 'age' : 30 }
   print 'Hello %(name)s, you are %(age)d years old.' % data

 One person's data is another person's program. 
                 -- Guy L. Steele, Jr.
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list