Rustom Mody <rustompm...@gmail.com> wrote: >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:
>> To the equivalent code with struct: > >> import struct > >> dscrp = "H?fs5B" > >> f = open('file.dat') >> stuff = struct.unpack( dscrp, f.read() ) > >> print stuff > >> In both cases, you have to KNOW the format of the data beforehand. If you >> do a read_short where you happen to have written a float, disaster ensues. > >> I don't really see that you've added very much. > >I thought much the same. >However notice your f.read(). Its type is string. > >What if file.dat is a 1GB wav file? f.seek(512000) stuff = struct.unpack( dscrp, f.read(128) ) The point is that files already know how to position themselves. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- https://mail.python.org/mailman/listinfo/python-list