try:
    return struct.unpack(fmt, astr)
except struct.error:
    flen = struct.calcsize(fmt.replace('*', ''))
alen = len(astr)
idx = fmt.find('*')
before_char = fmt[idx - 1]
n = (alen - flen) / struct.calcsize(before_char) + 1
fmt = ''.join((fmt[:idx - 1], str(n), before_char, fmt[idx + 1:]))
return struct.unpack(fmt, astr)
Unspecified byte lengths in Python