[Tutor] Re: Why is this write defined as a tuple, instead of picking list?

Andy Baker andy at andybak.net
Sat Apr 17 10:12:15 EDT 2004


> Date: Fri, 16 Apr 2004 23:07:17 +0100
> From: "Alan Gauld" <alan.gauld at blueyonder.co.uk>
> Subject: Re: [Tutor] Re: Why is this write defined as a 
> tuple,	instead
> 	of picking list?
> To: "Andrei" <project5 at redrival.net>,	<tutor at python.org>

<snip>

> > If
> > you want to concatenate strings, you should use "+":
> >
> >    write = "a" + "b" + "c"
> >
> > It is generally not recommended to use this, because it's slow. It's
> better
> > to have a list of substrings like this:
> >
> >   write = ["a", "b", "c"]
> >
> > and then use the string method join() to convert that list into a
> string
> 

Yuk!

> Or even use a format operator with the tuple:
> 
>     write = "%s%s%s" % ("a", "b", "c')
> 

Double Yuk!

> > In this particular (partial) case, I'd even recommend string
> formatting:
> >
> >   write = "<h3>%s</h3>" % article_items[0]
> 
> Yes in this case hard coding the <h3> makes even more sense!
> And formatting is pretty fast coz it happens in C.
> 
> Alan G.

I would prefer to go with concantenation for readabilityin most cases. Why
is concantenation so slow and could the Python developers speed it up rather
than force us to use the uglier syntax?




More information about the Tutor mailing list