Offering a refactor of write_header() on issue #337 we discussed today.
Created originally on Bitbucket by tuttle (Vlada Macek)
Was already merged in Bitbucket before import, marked as merged by the import user
The second commit is an optimization to remove possible many string comparisons. My CPython appears to optimize for it automatically (by string interning), but generally comparing integers appears to be better practice.