expand tuple in string

Mark Day mday at apple.com
Wed Oct 15 18:23:52 EDT 2003


In article <bmke70$o44u3$1 at ID-176487.news.uni-berlin.de>, Ansgar
Wollnik <wiseworld at web.de> wrote:

> I'd like to expand a tuple into a string (to use this for a MySQL-Select).
> 
> result=""
> tuple=('one','two','three')
> for element in tuple:
>  result=result+","+element
> 
> But this doesn't work. What can I do to get a string like this:
> 
> result="one, two, three"

The join method of strings:

>>> tuple=('one','two','three')
>>> result = ", ".join(tuple)
>>> result
'one, two, three'

-Mark




More information about the Python-list mailing list