Join equivalent for tuples of non-strings?

Peter L. Buschman plb at iotk.com
Thu Sep 18 14:00:30 EDT 2003


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, '.' )

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in -toplevel-
    string.join( bar, '.' )
  File "C:\Python23\Lib\string.py", line 135, in join
    return sep.join(words)
TypeError: sequence item 0: expected string, int found
>>> 

--PLB




More information about the Python-list mailing list