Marcus Goldfish wrote: > 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! Not without more information: What are you entering on the command line? What do you enter in the IPython shell to run the function? > > 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 > > ------------------------------------------------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Bob Gailer 510-978-4454 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor