does python could support sequence of short or int?

Diez B. Roggisch deets at nospam.web.de
Thu Mar 30 08:09:04 EST 2006


momobear wrote:

> then how can I convert it to a int list? I read about struct and array,
> I think they are not suitable, since I don't know how long will the
> buffer is. I know if I write a plugins modules in C should works, but
> that's really upset to tell to myself there is no way in Python.

You think wrong - they _are_ suitable. You can create the
struct.unpack-format string on the fly, which allows you to do this:

import struct
some_ints = range(1000)
v = struct.pack("%ih" % len(some_ints), *some_ints)
print struct.unpack("%ih" % len(some_ints), v)

Regards,

Diez






More information about the Python-list mailing list