packing (struct module)
Przemysław G. Gawroński
gawron at obop.com.pl
Wed Dec 8 06:47:38 EST 1999
I have a file with tab separated fields (posibly a different number in a
different file, but the same within the file). I would like to pack it
using some thing like this:
import struct
f = open( 'afile', 'r' )
lines = f.readlines()
packedLines = []
if len( lines ) > 0:
formatString = '1f' * lines[ 0 ].len()
for l in lines:
packedLines.append( struct.pack( formatString, l ))
At this moment I would have a list of packed strings in packedLines.
The problem is in the last line of code, since I cann't pass a list to
the pack function.
I would be very thank full, for sugestions on how to do this.
Thanks Przemek
More information about the Python-list
mailing list