Re: struct.unpack: why 's' fmt char convert to bytestring

2014-05-15 Thread MRAB
On 2014-05-15 13:34, GuoChao wrote: T he Python documentation gives this same example: record = b'raymond\x32\x12\x08\x01\x08' name, serialnum, school, gradelevel = unpack('<10sHHb', record) but get different results as to 's', don't kn

Re: struct.unpack: why 's' fmt char convert to bytestring

2014-05-15 Thread Dave Angel
On 05/15/2014 08:34 AM, GuoChao wrote: The Python documentation gives this same example:>>> record = b'raymond \x32\x12\x08\x01\x08' name, serialnum, school, gradelevel = unpack('<10sHHb', record) but get different results as to 's', don't know why this change in Python 3? need extra work

Re: struct.unpack() on a stream

2009-02-27 Thread Gabriel Genellina
En Fri, 27 Feb 2009 10:10:39 -0200, MRAB escribió: Gabriel Genellina wrote: En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt escribió: I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack(

Re: struct.unpack() on a stream

2009-02-27 Thread MRAB
Gabriel Genellina wrote: En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt escribió: I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack() stops complaining about a lack of data, but that sounds r

Re: struct.unpack() on a stream

2009-02-27 Thread Gabriel Genellina
En Fri, 27 Feb 2009 09:29:16 -0200, Ulrich Eckhardt escribió: I have a socket from which I would like to parse some data, how would I do that? Of course, I can manually read data from the socket until unpack() stops complaining about a lack of data, but that sounds rather inelegant. Any be

Re: struct.unpack less than 1 byte

2007-10-10 Thread Stargaming
On Wed, 10 Oct 2007 03:42:15 -0700, John Machin wrote: > On Oct 10, 8:15 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote: >> 2007/10/10, cprogrammer <[EMAIL PROTECTED]>: >> > i need to read from a file a struct like this [1byte, 12bits, 12bits] >> > reading 1 byte or more is not a problem ... but t

Re: struct.unpack less than 1 byte

2007-10-10 Thread John Machin
On Oct 10, 8:15 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote: > 2007/10/10, cprogrammer <[EMAIL PROTECTED]>: > > i need to read from a file a struct like this [1byte, 12bits, 12bits] > > reading 1 byte or more is not a problem ... but the 12 bits values > > are ... > > 12bits, 12bits == 3 byes a

Re: struct.unpack less than 1 byte

2007-10-10 Thread Michal Bozon
You are able to read single bits from file in C ? You'll have to read the bytes and than perform some bitwise operations on them to extract the bits > hello all, > > i need to read from a file a struct like this [1byte, 12bits, 12bits] > reading 1 byte or more is not a problem ... but the 12 bit

Re: struct.unpack less than 1 byte

2007-10-10 Thread Guilherme Polo
2007/10/10, cprogrammer <[EMAIL PROTECTED]>: > hello all, > > i need to read from a file a struct like this [1byte, 12bits, 12bits] > reading 1 byte or more is not a problem ... but the 12 bits values > are ... > > thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > 12bits, 12bit

Re: struct.unpack on 64-bit platforms

2006-06-29 Thread Jorgen Grahn
On 22 Jun 2006 09:30:26 -0700, Nadav Samet <[EMAIL PROTECTED]> wrote: ... > But apparently, on 64-bit platforms it tries to read 64-bit unsigned > integer (since > that's what the C Type unsigned long means on 64-bit platforms). On /some/ 64-bit platforms. Others let unsigned long be 32-bit and in

Re: struct.unpack on 64-bit platforms

2006-06-22 Thread Georg Brandl
Nadav Samet wrote: > Hi, > > I am trying to unpack a 32-bit unsigned integer from a string using > struct.unpack. > so using string.unpack('L', data) would work fine on 32-bit systems, > > But apparently, on 64-bit platforms it tries to read 64-bit unsigned > integer (since > that's what the C T

Re: struct.unpack

2005-10-03 Thread g.franzkowiak
Peter Otten schrieb: > g.franzkowiak wrote: > > >>The dataObject was read from a named pipe as an byte stream >> >>state, dataObject = win32file.ReadFile(handle, nbytes, None) >>print repr(dataObject) >> ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0. >> >>With Frederiks help operates this

Re: struct.unpack

2005-10-03 Thread Peter Otten
g.franzkowiak wrote: > The dataObject was read from a named pipe as an byte stream > > state, dataObject = win32file.ReadFile(handle, nbytes, None) > print repr(dataObject) > ==> '\x01\x02\x03\x04\x00\x00\x00\x00\x00\x00\x0. > > With Frederiks help operates this fine I do not doubt that. M

Re: struct.unpack

2005-10-03 Thread g.franzkowiak
Peter Otten schrieb: > g.franzkowiak wrote: > > >>tmpList = list(dataObject)[:4]) >>obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. > > > Have you tried just > > obj = dataObject[:4] > > without the intermediate list? If that failed, can you tell us the type of > the dataObject? E. g.

Re: struct.unpack

2005-10-02 Thread Peter Otten
g.franzkowiak wrote: > tmpList = list(dataObject)[:4]) > obj = tmpList[0]+tmpList[1]+tmpList[2]+tmpList[3]. Have you tried just obj = dataObject[:4] without the intermediate list? If that failed, can you tell us the type of the dataObject? E. g. >>> print type(dataObject) Peter -- http

Re: struct.unpack

2005-10-02 Thread g.franzkowiak
Fredrik Lundh schrieb: > "g.franzkowiak" wrote: > > >>I've read a pipe and store it in a object. >>My next step was the separation from 4 bytes with >>obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' >>and the converting by >>value = struct.unpack('I', obj) generated the error >>

Re: struct.unpack

2005-10-02 Thread Fredrik Lundh
"g.franzkowiak" wrote: > I've read a pipe and store it in a object. > My next step was the separation from 4 bytes with > obj = string.join(list(dataObject)[:4] ==> '\x16 \x00 \x00 \x00' > and the converting by > value = struct.unpack('I', obj) generated the error > "unpack str size does not matc