Is there any way to struct.unpack or struct.unpack_from into an existing
array.array or similar structure? I am unpacking file data in a loop and i
was hoping to find something that performs better than simply unpacking into
a new tuple each iteration.
Thanks in advance,
Rich
--
http://mail.python
On Fri, Jun 13, 2008 at 9:27 PM, Ping Zhao <[EMAIL PROTECTED]> wrote:
> However, when I tried to rewrite them in short:
>
> header = struct.unpack('2s1i', self.__read(src, 6))
> ...
> It was weired that the required argument length increased to 8.
This is an alignment issue; if you don't specify a
Ping Zhao wrote:
> I am writing a small program to decode MS bitmap image. When I use
> statements as follow, it works fine:
>
> header['sig'] = str(struct.unpack('2s', self.__read(src, 2))[0])
> header['len'] = int(struct.unpack('1i', self.__read(src, 4))[0])
>
> However, when I tried to rewr
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi,
I am writing a small program to decode MS bitmap image. When I use statements
as follow, it works fine:
header['sig'] = str(struct.unpack('2s', self.__read(src, 2))[0])
header['len'] = int(struct.unpack('1i', self.__read(src, 4))[0])
However,
"brnstrmrs" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> If I run:
>
> testValue = '\x02\x00'
> junk = struct.unpack('h', testValue)
>
> Everything works but If I run
>
> testValue = raw_input("Enter Binary Code..:") inputting at the
> console '\x02\x00'
> junk = struct.unpack('
On Mar 17, 11:00 pm, brnstrmrs <[EMAIL PROTECTED]> wrote:
> If I run:
>
> testValue = '\x02\x00'
> junk = struct.unpack('h', testValue)
>
> Everything works but If I run
>
> testValue = raw_input("Enter Binary Code..:") inputting at the
> console '\x02\x00'
> junk = struct.unpack('h', testValue)
>
>
> testValue = '\x02\x00'
> junk = struct.unpack('h', testValue) #Works
>
> testValue = raw_input("Enter Binary Code..:") inputting at the
> console '\x02\x00'
> junk = struct.unpack('h', testValue)
>
> error: unpack requires a string argument of length 2
Well, it thinks the length of the test
If I run:
testValue = '\x02\x00'
junk = struct.unpack('h', testValue)
Everything works but If I run
testValue = raw_input("Enter Binary Code..:") inputting at the
console '\x02\x00'
junk = struct.unpack('h', testValue)
It errors out with
Traceback (most recent call last):
File "/home/nirmal/
Good point. Hadn't thouhgt of that.
Thanks
Grant
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> what concerns me though is that although the file is opened in binary
> mode,
> "for line.." has a problem reading the file correctly.
There is _no_ correct way of splitting a file containing binary data in
lines because binary data may contain newline bytes that do not
Hi ,
Thanks for the tip regarding checking the length of line. I discovered
that on the problem record it was short by a few bytes. After changing
the read method from "for line in.." to "infile.read(n)" my problem was
solved,
what concerns me though is that although the file is opened in binary
m
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> except when line[86:90] contains "carriage-return" "linefeed"
> which are valid binary packed values.
You probably don't want to be reading binary data a
line at a time, if that's what you're doing.
--
http://mail.python.org/mailma
[EMAIL PROTECTED] wrote:
> I am pretty new to python and am having a problem
> intepreting binary data using struct.unpack.
> I am reading a file containing binary packed data
> using open with "rb". All the values are coming through
> fine when using (integer1,) = struct.unpack('l', line[86:90])
Hi All,
I am pretty new to python and am having a problem
intepreting binary data using struct.unpack.
I am reading a file containing binary packed data
using open with "rb". All the values are coming through
fine when using (integer1,) = struct.unpack('l', line[86:90])
except when line[86:90] con
14 matches
Mail list logo