bug in string.join()?

Tim Hochberg tim.hochberg at ieee.org
Thu Feb 22 16:13:23 EST 2001


"Adam DePrince" <adam at deprince.net> wrote in message
[SNIP]
> When constructing strings from lists the default value of ' ' as a
> delimiter is a pain.  Consider that string.join is often used to replace
> string interpolation.  Consider this straw man:
>
> queries = []
> for ....
> queries.append("insert into table xyz values '%s','%s','%s' ....
>
> One might prefer to say
>
> queries = []
> for .....
> queries.append( map( str, ["insert into table xyz values '", d1, "','"
> ...
> 
> queries = map( string.join, queries )
>
> Of course, for this to work, you would have to say:
>
> queries = map( string.join, queries, ("",)*len(queries))

Death to map! Use list comprehensions instead. And string methods! New is
good, old is bad <0.9 wink>.

   queries = [''.join(q) for q in queeries]

[SNAP]

-tim





More information about the Python-list mailing list