Representing tuples in strings

Delaney, Timothy tdelaney at
Tue Oct 30 02:08:55 CET 2001

> From: Graham Ashton [mailto:graz at]
>   >>> mytup = ('string1', 3, 'string2')
>   >>> ", ".join(map(str, mytup))
>   'string1, 3, string2'

You were so close ...

t = ('string 1', 3, 'string 2',)
s = ', '.join(map(repr, t))
print s
print repr(s)

'string 1', 3, 'string 2'
"'string 1', 3, 'string 2'"

The line with repr() in it is what you would see if you didn't have the
print statements, and you were working on the interactive prompt (which you
obviously are). Personally, I never work with the interactive prompt, as the
results are different to what they would be run as a script, and eventually
you want to run everything as a script.

Tim Delaney

More information about the Python-list mailing list