tuple to string?
hongqn at gmail.com
Fri Jul 22 17:48:19 CEST 2005
Francois De Serres 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
.>>> t = (0x73, 0x70, 0x61, 0x6D)
(use string formatter):
.>>> '%c%c%c%c' % t
(use struct model):
.>>> import struct
.>>> struct.pack('bbbb', *t)
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
More information about the Python-list