"John" <[EMAIL PROTECTED]> wrote

> packing it into a dictionary. It works, but somehow doesn't seem so
> 'pythonic'. Just seeking comments on how I might make it more 
> efficient.

I don't think its too bad but I'd probably try reading all the data in 
one go.

> #Define Header format
> Dfmt=['i','i','i','13s','i','i','i','i','i','i','i','f','f','i','i','f','f','i','i','i']

Dfmt = "iii13siiiiiiiiiiiiiiii"
ln = 19 * struct.calcsize('i') + struct.calcsize('13s')
a = struct.unpack(Dfmt,f2.read(ln))

Which should return a tuple of all your values in one go.
Now you can go straight to the last for loop below...

All untested of course! :-)


> #format for binary reading first bits
> if f2:
>  print filename + ' has been opened'
>  #create a dictionary from header file
>  a=[struct.unpack(ft,f2.read(struct.calcsize(ft))) for ft in Dfmt]
>  for i in range(len(a)):
>   B[I[i]]=a[i][0]

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to