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

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

2014-05-15 Thread GuoChao
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 to encode...>>> name >>> 'raymond '

Re: issue with struct.unpack

2012-08-28 Thread 9bizy
x27; > > >> > > > >> That opens the file again and 'list' causes it to read the file as > > >> though it were a series of lines in a text file, which, as I've said, > > >> it looks like it isn't. The list of 'li

Re: issue with struct.unpack

2012-08-28 Thread MRAB
> > data.append(list((file('s_data.xls' >> > >> That opens the file again and 'list' causes it to read the file as >> though it were a series of lines in a text file, which, as I've said, >> it looks like it isn't. The list o

Re: issue with struct.unpack

2012-08-28 Thread 9bizy
> > > > > data.append(list((file('s_data.xls' > > > > > That opens the file again and 'list' causes it to read the file as > > though it were a series of lines in a text file, which, as I've said, > > it looks like

Re: issue with struct.unpack

2012-08-28 Thread MRAB
of 'lines' is appended to the list 'data', so that's a list of lists. data = struct.unpack('!B4HH', data) print "s_data.csv: ", data I tries so many format for the struct.unpack but I got this errors: Traceback (most recent call last):

Re: issue with struct.unpack

2012-08-28 Thread MRAB
On 28/08/2012 23:35, 9bizy wrote: On Saturday, 25 August 2012 20:16:54 UTC+1, MRAB wrote: On 25/08/2012 19:34, 9bizy wrote: > I am trying to unpack values from sensor data I am retrieving through > a serial cable, but I get errors while using struct.unpack, how can I > use struct.

Re: issue with struct.unpack

2012-08-28 Thread 9bizy
On Saturday, 25 August 2012 20:16:54 UTC+1, MRAB wrote: > On 25/08/2012 19:34, 9bizy wrote: > > > I am trying to unpack values from sensor data I am retrieving through > > > a serial cable, but I get errors while using struct.unpack, how can I > > > use struct.

Re: issue with struct.unpack

2012-08-28 Thread 9bizy
This is what I have to reproduce the challenge I am having below: import csv import struct data = [] for Node in csv.reader(file('s_data.xls')): data.append(list((file('s_data.xls' data = struct.unpack('!B4HH', data) print "s_data.c

Re: issue with struct.unpack

2012-08-26 Thread Alexander Blinne
On 26.08.2012 01:31, Dennis Lee Bieber wrote: > The struct module relies upon the user knowing the format of the data. > If your problem is that you have some null-terminated string data in a > variable width field, you will have to locate the position of the null > FIRST, and specify the appropria

Re: issue with struct.unpack

2012-08-25 Thread MRAB
On 25/08/2012 19:34, 9bizy wrote: I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? I checked the python documentation for struct and I can seen

Re: issue with struct.unpack

2012-08-25 Thread Mark Lawrence
On 25/08/2012 19:34, 9bizy wrote: I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? I checked the python documentation for struct and I can seen

issue with struct.unpack

2012-08-25 Thread 9bizy
I am trying to unpack values from sensor data I am retrieving through a serial cable, but I get errors while using struct.unpack, how can I use struct.unpack to unload the data in a readable format? I checked the python documentation for struct and I can seen to find any argument for this. I

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

struct.unpack() on a stream

2009-02-27 Thread Ulrich Eckhardt
Hi! 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 better suggestions? Uli -- Sator Laser GmbH Geschäftsführer: Tho

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
; > are ... > > 12bits, 12bits == 3 byes and 8 + 12 + 12 = 32 :-) Assuming little-endianess and that all 3 items are unsigned: >>> import struct >>> bytes = "\x21\x43\xba\xdc" >>> i32 = struct.unpack(">> hex(i32) '0xdcba4321L'

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

struct.unpack less than 1 byte

2007-10-10 Thread cprogrammer
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

Re: Qustion about struct.unpack

2007-05-01 Thread OhKyu Yoon
>>> On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote: > >>> > I have a really long binary file that I want to read. >>> > The way I am doing it now is: >>> >>> > for i in xrange(N): # N is about 10,000,000 >>> > time = st

Re: Qustion about struct.unpack

2007-05-01 Thread Gabriel Genellina
ead. >> > The way I am doing it now is: >> >> > for i in xrange(N): # N is about 10,000,000 >> > time = struct.unpack('=', infile.read(8)) >> > # do something >> > tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32)) >>

Re: Qustion about struct.unpack

2007-05-01 Thread eC
On Apr 30, 9:41 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote: > > Hi! > > I have a really long binary file that I want to read. > > The way I am doing it now is: > > > for i in xrange(N): # N is abou

Re: Qustion about struct.unpack

2007-04-30 Thread Steven D'Aprano
On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote: > Hi! > I have a really long binary file that I want to read. > The way I am doing it now is: > > for i in xrange(N): # N is about 10,000,000 > time = struct.unpack('=', infile.read(8)) > # do some

Qustion about struct.unpack

2007-04-30 Thread OhKyu Yoon
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=', infile.read(8)) # do something tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32)) # do someth

Re: error: Error -5 while decompressing data from struct.unpack

2006-12-14 Thread Fredrik Lundh
Gary Robinson wrote: > One of our users received an exception, "error: Error -5 while > decompressing data from struct.unpack," in the course of a > struct.unpack operation. I haven't been able to discern what Error -5 > is in this context. In experiments here I

error: Error -5 while decompressing data from struct.unpack

2006-12-14 Thread Gary Robinson
One of our users received an exception, "error: Error -5 while decompressing data from struct.unpack," in the course of a struct.unpack operation. I haven't been able to discern what Error -5 is in this context. In experiments here I wasn't able to elicit that exceptio

Re: Type discrepancy using struct.unpack

2006-10-19 Thread Pieter Rautenbach
> > 2006 x86_64 x86_64 x86_64 GNU/Linux > > > > Consider the following two snippets, issuing a struct.unpack(...) using > > Python 2.3.4 and Python 2.5 respectively. > > > > [EMAIL PROTECTED] pymsnt-0.11.2]$ python > > Python 2.5 (r25:51908, Oct 17 20

Re: Type discrepancy using struct.unpack

2006-10-19 Thread Leo Kislov
Consider the following two snippets, issuing a struct.unpack(...) using > Python 2.3.4 and Python 2.5 respectively. > > [EMAIL PROTECTED] pymsnt-0.11.2]$ python > Python 2.5 (r25:51908, Oct 17 2006, 10:34:59) > [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 > Type "help", &

Type discrepancy using struct.unpack

2006-10-19 Thread Pieter Rautenbach
Hallo, I have a 64 bit server with CentOS 4.3 installed, running Python. [EMAIL PROTECTED] pymsnt-0.11.2]$ uname -a Linux lutetium.mxit.co.za 2.6.9-34.ELsmp #1 SMP Thu Mar 9 06:23:23 GMT 2006 x86_64 x86_64 x86_64 GNU/Linux Consider the following two snippets, issuing a struct.unpack(...) using

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 >

struct.unpack on 64-bit platforms

2006-06-22 Thread Nadav Samet
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 Type unsigned long

Re: Question about struct.unpack

2006-02-22 Thread Scott David Daniels
Eric Jacoboni wrote: > But : >> nom = nomz.rstrip('\0') > > doesn't work for me: > nomz > 'Dupont\x00\x80\xbf\xff\xf70\x8f\xe0u\xa4\x00\x00.8\xfe\xfe\xfe\xff\x80\x80\x80\x80' > nom = nomz.rstrip('\0') nom > 'Dupont\x00\x80\xbf\xff\xf70\x8f\xe0u\xa4\x00\x00.8\xfe\xfe\xfe\xff\x8

Re: Question about struct.unpack

2006-02-22 Thread Eric Jacoboni
Scott David Daniels <[EMAIL PROTECTED]> writes: Thanks for your explanations. But : > nom = nomz.rstrip('\0') doesn't work for me: >>> nomz 'Dupont\x00\x80\xbf\xff\xf70\x8f\xe0u\xa4\x00\x00.8\xfe\xfe\xfe\xff\x80\x80\x80\x80' >>> nom = nomz.rstrip('\0') >>> nom 'Dupont\x00\x80\xbf\xff\xf70\

Re: Question about struct.unpack

2006-02-22 Thread Scott David Daniels
ze 46) in C takes no more room. the alignment to the end shows up in a C sizeof. data = struct.pack('30sdic', 'John Q. Public', 57123.25, 43, 'M') nomz, taille, age, plop = struct.unpack('30sdic', data) nom = nomz.rstrip('\0') --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Question about struct.unpack

2006-02-22 Thread Eric Jacoboni
Hi, To experiment with unpacking, i've written a little C code which stores one record in a file. Then, i try to reread this file to unpack the record. Here's the struct of a record: typedef struct { char nom[30]; double taille; int age; char plop; } enreg_t; The whole

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 convert

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',

struct.unpack

2005-10-02 Thread g.franzkowiak
Hello Everybody, 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 "unpa

Problem with struct.unpack

2005-07-01 Thread Kuner Martin
Title: Problem with struct.unpack Hi all, I have the following question/problem: >>> import struct >>> strBuffer = u'\x00\xf0\x00\x00\x00\x00\x00\x00' >>> print "%r" % strBuffer u'\x00\xf0\x00\x00\x00\x00\x00\x00' >>>

Re: Struggling with struct.unpack() and "p" format specifier

2004-12-01 Thread Geoffrey
and read it with multiple > > statements, I am just looking for a more efficient solution. > > This looks like about the best you can do, using the information > from Tim's reply: > > >>> buf = '\0\0\xb9\x02\x13EXCLUDE_CREDIT_CARD' > >>> import

Re: Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Peter Hansen
Peter Hansen wrote: I would be inclined to say that the "p" format in struct (using Python 2.4rc1 or Python 2.3.3) does not act as documented on Windows XP SP2, at least... I hope we've both just missed something obvious. Okay, we were certainly missing something, but I don't believe I would call i

Re: Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Peter Hansen
>>> import struct >>> x = struct.unpack('>xxBB%sp' % (ord(buf[4])+1), buf) >>> x (185, 2, 'EXCLUDE_CREDIT_CARD') If you wanted to avoid hard-coding the 4, you would be most correct to do this: header = '>xxBB' lenIndex = struct.calcsize(h

Re: Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Peter Hansen
Geoffrey wrote: I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; ... As I read the documentation the "p" format string seems to address this situation, where the number bytes of the string to read is the first byt

Re: Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Tim Peters
ell, the docs mean it when they say: Note that for unpack(), the "p" format character consumes count bytes You don't have an explicit count in front of your "p" code, so count defaults to 1, so only one byte of xbuffer will get consumed. This works, tell

Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Geoffrey
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer: '\x00\x00\xb9\x02\x13EXCLUDE_CREDIT_CARD' # the above was printed using repr(xbuffer). # Note that int(0x13) = 19 which is exactl