QH> On 7/22/05, Francois De Serres <[EMAIL PROTECTED]> wrote:
>> what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) to
>> the string 'spam'?

QH> Use ''.join and chr() as others have pointed out.  Here are
QH> just-for-fun versions  ;)

.> t = (0x73, 0x70, 0x61, 0x6D)

QH> (use string formatter):
.> '%c%c%c%c' % t

Or more generally:

>>> t = (0x73, 0x70, 0x61, 0x6D)
>>> '%c'*len(t) % t
'spam'

but that's VERY perlonic python.  Still, it's a technique that can
come in handy when building, say, SQL queries on the fly.

-- 
Patricia J. Hawkins
Hawkins Internet Applications
www.hawkinsia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to