writing and parsing text files ||writing text is easybut reading it back can be problematicso we need to choose the structure carefully so that it is not too difficult to parse figure shows an example aircraft incident record in the text format we are going to use when we write the incident records to file we will follow each one with blank linebut when we parse the file we will accept zero or more blank lines between incident records writing text |each incident record begins with the report id enclosed in brackets ([]this is followed by all the one-line data items written in key=value form for the multiline narrative text we precede the text with start marker narrative_start and follow it with an end marker narrative_end )and we indent all the text in between to ensure that no line of text could be confused with start or end marker [ cdateaircraft_id= aircraft_type=dhc- -mk airport=merle (mudholesmith pilot_percent_hours_on_type= pilot_total_hours= midair= narrative_start according to the pilotthe drag link failed due to an oversized tail wheel tire landing on hard surface narrative_end figure an example text format aircraft incident record here is the code for the export_text(functionbut excluding the except and finally blocks since they are the same as ones we have seen beforeexcept for the exceptions handleddef export_text(selffilename)wrapper textwrap textwrapper(initial_indent="subsequent_indent=" introduces various parsing techniquesincluding two third-party open source parsing modules that make parsing tasks much easier