table bytes and bytearray methods # syntax description upper(returns an ascii-uppercased copy of bytes/bytearray zfill(wreturns copy of bwhich if shorter than is padded with leading zeros ( charactersto make it bytes long we have omitted the except and finally blocks since they are the same as the ones shown in the preceding subsectionapart from the particular exceptions that the except block catches we begin by opening the file in "write binarymodeeither normal file or gzip compressed file depending on the compress flag we then write the -byte magic number that is (hopefullyunique to our programand the -byte version number using version number makes it easier to change the format in the future--when we read the version number we can use it to determine which code to use for reading next we iterate over all the incidentsand for each one we create bytearray we add each item of data to the byte arraystarting with the variable length strings the date toordinal(method returns single integer representing the stored datethe date can be restored by passing this integer to the datetime date fromordinal(method the numbersstruct is defined earlier in the program with this statementnumbersstruct struct struct("<idi?"this format specifies little-endian byte orderan unsigned -bit integer (for the date ordinal) -bit float (for the percentage hours on type) -bit integer (for the total hours flown)and boolean (for whether the incident was midairthe structure of an entire aircraft incident record is shown schematically in figure once the bytearray has all the data for one incidentwe write it to disk and once all the incidents have been written we return true (assuming no error occurredthe finally block ensures that the file is closed just before we return reading back the data is not as straightforward as writing it--for one thing we have more error checking to do alsoreading back variable length strings is slightly tricky here is the start of the import_binary(method and the complete nested unpack_string(function that we use to read back the variable length stringsthere is no central repository for magic numbers like there is for domain namesso we can never guarantee uniqueness