On Fri, May 28, 2010 at 12:56 PM, Noufal Ibrahim <nou...@gmail.com> wrote:
> On Fri, May 28, 2010 at 12:49 PM, murugadoss <murugadoss2...@gmail.com> > wrote: > > Hello all, > > > > I am trying a sample program for send set of data [ kept in array]. I > have > > attached the code below, > > > > import struct > > > > sendvalues = [181, 98, 11, 01] > > for i in range(4): > > snddata = struct.pack('int',int(sendvalue[i])) > > sendto(sndData,("localhost")) > Just do this. >>> l=[181, 98, 11, 01] >>> b=struct.pack('H'*4, *l) >>> b '\xb5\x00b\x00\x0b\x00\x01\x00' >>> struct.unpack('H'*4,b) (181, 98, 11, 1) Since your integers are small you can use "unsigned short" for which the specifier is 'H'. If you have any doubts, ask. -- --Anand _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers