tuple to string?

deelan ggg at zzz.it
Fri Jul 22 09:11:36 EDT 2005


Francois De Serres wrote:
> hiho,
> 
> what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) to 
> the string 'spam'?

one way is to use a list expression:

 >>> ''.join([chr(c) for c in (0x73, 0x70, 0x61, 0x6D)])
'spam'

another is to use map:

 >>> ''.join(map(chr, (0x73, 0x70, 0x61, 0x6D)))
'spam'

HTH,
deelan.

-- 
deelan, #1 fan of adriana lima!
<http://www.deelan.com/>







More information about the Python-list mailing list