structread

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Oct 20 06:52:21 EDT 2009


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>.



More information about the Python-list mailing list