tuple to string?

Robert Kern rkern at ucsd.edu
Fri Jul 22 09:07:28 EDT 2005


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

In [1]: t = (0x73, 0x70, 0x61, 0x6D)

In [2]: ''.join(chr(x) for x in t)
Out[2]: 'spam'

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list