<i>That's my module. Now, how can I make it better?</i><p>You could have those fields know their own sizes, and then you could have Struct subclasses know the size of their instances, so you don't have to call sizeof. E.g.:<p><pre><code> class DataHeader(Struct):
address = newstruct.long()
typ = newstruct.byte()
tag = newstruct.short()
data = newstruct.byte(length=40) # 40 bytes
>>> fp = open('mydata', 'rb')
>>> dh = DataHeader.read(fp)
# or perhaps: DataHeader.load(fp.read(len(dh)))
# this way the side-effect of moving fp's current position is more explicit
>>> fp.close()
>>> len(dh)
12345 # or whatever, sum of sizes for long, 41 bytes, and short</code></pre>