M
Mark
Hi;
I'm trying to use the struct.unpack to extract an int, int, char
struct info from a file. I'm more accustomed to the file.readlines
which works well in a 'for' construct (ending loop after reaching
EOF).
# This does OK at fetching one 10-byte string at a time:
# (4, 4, 2 ascii chars representing hex)
info1, info2, info3 = struct.unpack('<IIH', myfile.read(10))
# Now to do the entire file, putting into a loop just gives error:
# TypeError: 'int' object is not iterable
for info1, info2, info3 in struct.unpack('<IIH', myfile.read(10)):
In trying to shoehorn this into a 'for' loop I've been unsuccessful.
I also tried other variations that also didn't work but no point
wasting space. Using Python 2.5, WinXP
Thx,
Mark
I'm trying to use the struct.unpack to extract an int, int, char
struct info from a file. I'm more accustomed to the file.readlines
which works well in a 'for' construct (ending loop after reaching
EOF).
# This does OK at fetching one 10-byte string at a time:
# (4, 4, 2 ascii chars representing hex)
info1, info2, info3 = struct.unpack('<IIH', myfile.read(10))
# Now to do the entire file, putting into a loop just gives error:
# TypeError: 'int' object is not iterable
for info1, info2, info3 in struct.unpack('<IIH', myfile.read(10)):
In trying to shoehorn this into a 'for' loop I've been unsuccessful.
I also tried other variations that also didn't work but no point
wasting space. Using Python 2.5, WinXP
Thx,
Mark