tuple to string?

Qiangning Hong hongqn at gmail.com
Fri Jul 22 12:17:25 EDT 2005


On 7/22/05, Francois De Serres <fdeserres at gmx.net> wrote:
> what's the clean way to translate the tuple (0x73, 0x70, 0x61, 0x6D) to
> the string 'spam'?

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

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

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

(use struct model):
.>>> import struct
.>>> struct.pack('bbbb', *t)
'spam' 

-- 
Qiangning Hong

I'm usually annoyed by IDEs because, for instance, they don't use VIM
as an editor. Since I'm hooked to that, all IDEs I've used so far have
failed to impress me.
   -- Sybren Stuvel @ c.l.python

Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>



More information about the Python-list mailing list