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!<br><br>import struct
<br><br>def demux(filename, channel, nchannels):<br> "Demultiplexes a stream of shorts (signed int16) from a file."<br> fmt = str(nchannels) + 'h'<br> sz = struct.calcsize(fmt)<br><br> infile = open(fname, 'rb')
<br> chunk = infile.read(sz)<br> while chunk:<br> x = struct.unpack(fmt, chunk)<br> chunk = infile.read(sz)<br> infile.close()<br><br>#struct.error: unpack str size does no match format<br><br>