[Tutor] curious struct problem
Marcus Goldfish
magoldfish at gmail.com
Fri Feb 2 21:16:19 CET 2007
I'm trying to read a binary file using struct. This code works
interactively in the IPython shell, but not as a function invoked from a
command line (Windows). Can someone point out my error? Thanks!
import struct
def demux(filename, channel, nchannels):
"Demultiplexes a stream of shorts (signed int16) from a file."
fmt = str(nchannels) + 'h'
sz = struct.calcsize(fmt)
infile = open(fname, 'rb')
chunk = infile.read(sz)
while chunk:
x = struct.unpack(fmt, chunk)
chunk = infile.read(sz)
infile.close()
#struct.error: unpack str size does no match format
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070202/0b0db4d4/attachment.html
More information about the Tutor
mailing list