Terry J. Reedy <tjre...@udel.edu> added the comment: I agree that the _sampwidth multiplier is needed regardless of endianness.
The simplest option would be to pull the _datawritten statement out of the alternation, making the code read if self._sampwidth > 1 and big_endian: import array data = array.array(_array_fmts[self._sampwidth], data) data.byteswap() data.tofile(self._file) else: self._file.write(data) self._datawritten = self._datawritten + len(data) * self._sampwidth Note: while _sampwidth is initialized to 0, _ensure_header_written() checks that it is not 0, and it is used elsewhere as a divisor. The above adds a usually unneeded multiply by 1, but the alternative requires duplication of _file.write and two _datawritten statements if self._sampwidth > 1: if big_endian: import array data = array.array(_array_fmts[self._sampwidth], data) data.byteswap() data.tofile(self._file) else: # little_endian self._file.write(data) self._datawritten = self._datawritten + len(data) * self._sampwidth else: # _sampwidth == 1 self._file.write(data) self._datawritten = self._datawritten + len(data) This module is new to me. Can you think of any way to test this issue, perhaps by writing to StringIO file? This is not a heavily tested module ;-) In 3.3, the openfp synonym for open could perhaps be deprecated. ---------- nosy: +terry.reedy versions: +Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11126> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com