converting to string

Peter Hansen peter at
Wed Aug 4 14:01:05 CEST 2004

Gandalf wrote:

> Ajay Brar wrote:
>> how do i go about converting a Python object or tuple to a string.
> For special cases you can find a more efficient solution.For example, 
> for tuples of integers,
> you can write a C extension that allocates a big string and copies every 
> int object into 4 bytes
> in the string. That would be more efficient.

A C extension?  You mean like this? :

 >>> s = (1, 55, 109, 2000, 65535)
 >>> import struct
 >>> struct.pack('%si' % len(s), *s)



More information about the Python-list mailing list