Representing tuples in strings
Carl Banks
idot at vt.edu
Mon Oct 29 20:20:34 EST 2001
Graham Ashton <graz at mindless.com> wrote:
> I'm looking to convert the tuple:
>
> ('string1', 3, 'string2')
>
> to the string representation:
>
> 'string1', 3, 'string2'
>
> without resorting to a regular expression.
repr(('string1', 3, 'string2'))[1:-1]
> So far the nearest I've managed to get to is to have quotes round the
> whole thing, but not around the strings themselves. I suppose what I want
> here really is some better function to pass into map(). Maybe...
>
> >>> mytup = ('string1', 3, 'string2')
> >>> ", ".join(map(str, mytup))
> 'string1, 3, string2'
>
> Any thoughts? It's not exactly going to make the difference between life
> and death in my application (it's for log files), but I'd really like to
> learn some map/lambda tricks.
You want repr.
--
CARL
More information about the Python-list
mailing list