Join equivalent for tuples of non-strings?

Ulrich Petri ulope at gmx.de
Thu Sep 18 16:30:36 EDT 2003


"Peter L. Buschman" <plb at iotk.com> schrieb im Newsbeitrag
news:1a884f4a.0309181000.749eb8a1 at posting.google.com...
> I'm trying to think in Python, but am stumped here...
>
> What is the equivalent for the following if you are dealing with a tuple
> of non-strings?
>
> >>> import string
> >>> foo = ( '1', '2', '3' )
> >>> string.join( foo, '.' )
> '1.2.3'
>
> With a tuple of integers, this fails with a traceback as below:
>
> >>> bar = ( 1, 2, 3 )
> >>> string.join( bar, '.' )
>

try:

foo = (1,2,3,4,5,6)
".".join([str(x) for x in foo])

HTH

Ciao Ulrich






More information about the Python-list mailing list