code: def chunks(seq, size=None, dfmt="f", byte_order=None, padval=0.):
    
    if size is None:
      size = chunks.size
    dfmt = str(size) + dfmt
    if byte_order is None:
      struct_string = dfmt
    else:
      struct_string = byte_order + dfmt
    s = struct.Struct(struct_string)
    for block in blocks(seq, size, padval=padval):
      yield s.pack(*block)
docs: Chunk generator based on the struct module (Python standard library).
  
    Low-level data blockenizer for homogeneous data as a generator, to help
    writing an iterable into a file.
    The dfmt should be one char, chosen from the ones in link:
  
      `<http://docs.python.org/library/struct.html#format-characters>`_
  
    Useful examples (integer are signed, use upper case for unsigned ones):
  
    - "b" for 8 bits (1 byte) integer
    - "h" for 16 bits (2 bytes) integer
    - "i" for 32 bits (4 bytes) integer
    - "f" for 32 bits (4 bytes) float (default)
    - "d" for 64 bits (8 bytes) float (double)
  
    Byte order follows native system defaults. Other options are in the site:
  
      `<http://docs.python.org/library/struct.html#struct-alignment>`_
  
    They are:
  
    - "<" means little-endian
    - ">" means big-endian
  
    Note
    ----
    Default chunk size can be accessed (and changed) via chunks.size.