Style help for a Smalltalk-hack

Ian Kelly ian.g.kelly at gmail.com
Tue Oct 23 13:46:37 EDT 2012


On Tue, Oct 23, 2012 at 9:13 AM, Travis Griggs <travisgriggs at gmail.com> wrote:
>
> On Oct 22, 2012, at 6:33 PM, MRAB <python at mrabarnett.plus.com> wrote:
>
>> Another way you could do it is:
>>
>> while True:
>>    chunk = byteStream.read(4)
>>    if not chunk:
>>        break
>>    ...
>>
>> And you could fetch multiple signatures in one read:
>>
>> signatures = list(struct.unpack('>{}I'.format(valveCount), byteStream.read(4 * valueCount)))
>
> Thanks, both great ideas. Still does the read/decode slightly different between the different sites, but at least it's localized better. Much appreciated.

Another small optimization would be to read the gap and the valveCount together:

chunk = byteStream.read(8)
...
gap, valveCount = struct.unpack('>2l', chunk)



More information about the Python-list mailing list