structread

  • Thread starter Lawrence D'Oliveiro
  • Start date
L

Lawrence D'Oliveiro

This routine is so useful, I wonder there's nothing like it in module
struct, or anywhere else I'm aware of:

def structread(fromfile, decode_struct) :
"""reads sufficient bytes from fromfile to be unpacked according to
decode_struct, and returns the unpacked results."""
return struct.unpack(decode_struct, fromfile.read(struct.calcsize(decode_struct)))
#end structread

For a non-trivial example of its use, see
<http://www.codecodex.com/wiki/index.php?title=Reading_time_zone_files>.
 
A

Aahz

This routine is so useful, I wonder there's nothing like it in module
struct, or anywhere else I'm aware of:

def structread(fromfile, decode_struct) :
"""reads sufficient bytes from fromfile to be unpacked according to
decode_struct, and returns the unpacked results."""
return struct.unpack(decode_struct, fromfile.read(struct.calcsize(decode_struct)))
#end structread

Guido is generally opposed to simple one-liners.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top