Re: tuple to string?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: tuple to string?

From: John Machin <sjmachin@lexicon.net>
Date: Sat Jul 23 2005 - 00:51:55 CEST

Reinhold Birkenfeld wrote:
> Berthold Höllmann wrote:
>
>>Francois De Serres <fdeserres@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 :-)
Received on Thu Sep 29 17:06:54 2005