tuple to string?

John Machin sjmachin at lexicon.net
Sat Jul 23 09:31:04 EDT 2005


Reinhold Birkenfeld wrote:
> John Machin wrote:
> 
>>Reinhold Birkenfeld wrote:
>>
>>>Berthold Höllmann wrote:
>>>
>>>
>>>>Francois De Serres <fdeserres at gmx.net> writes:
>>>>
>>>>
>>>>
>>>>>hiho,
>>>>>
>>>>>what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D)
>>>>>to the string 'spam'?
>>>>
>>>>.>>> t = (0x73, 0x70, 0x61, 0x6D)
>>>>.>>> ''.join('%c' % c for c in t)
>>>>'spam'
>>>
>>>
>>>Or:
>>>
>>>t = (0x73, 0x70, 0x61, 0x6D)
>>>('%c' * len(t)) % t
>>
>>You don't need the sissy parentheses; '%c' * len(t) % t works just fine :-)
> 
> 
> Ah, ok. Didn't want to lookup the precedence rules...


Look up the precedence rules? Are you aware of any language where * / 
and % _don't_ have the same precedence??



More information about the Python-list mailing list