file handling "en wikipedia org"the format will be "< (little-endian byte order -byte unsigned integer -byte byte string)and the bytes object that is returned will be '\ \ en wikipedia orgconvenientlypython shows bytes objects in compact form using printable ascii characters where possibleand hexadecimal escapes (and some special escapes like \ and \notherwise the pack_string(function can handle strings of up to utf- characters we could easily switch to using different kind of integer for the byte countfor examplea -byte signed integer (format " "would allow for strings of up to - (more than billioncharacters the struct module does provide similar built-in format" "that stores single byte as character count followed by up to characters for packingthe code using "pformat is slightly simpler than doing all the work ourselves but "pformat restricts us to maximum of utf- characters and provides almost no benefit when unpacking (for the sake of comparisonversions of pack_string(and unpack_string(that use "pformat are included in the convert-incidents py source file we can now turn our attention to the rest of the code in the export_binary(method fh none tryif compressfh gzip open(filename"wb"elsefh open(filename"wb"fh write(magicfh write(format_versionfor incident in self values()data bytearray(data extend(pack_string(incident report_id)data extend(pack_string(incident airport)data extend(pack_string(incident aircraft_id)data extend(pack_string(incident aircraft_type)data extend(pack_string(incident narrative strip())data extend(numbersstruct packincident date toordinal()incident pilot_percent_hours_on_typeincident pilot_total_hoursincident midair)fh write(datareturn true