parsing text |the method for reading and parsing text format aircraft incident records is longer and more involved than the one used for writing when reading the file we could be in one of several states we could be in the middle of reading narrative lineswe could be at key=value lineor we could be at report id line at the start of new incident we will look at the import_text_manual(method in five parts def import_text_manual(selffilename)fh none tryfh open(filenameencoding="utf "self clear(data {narrative none the method begins by opening the file in "read textmode then we clear the dictionary of incidents and create the data dictionary to hold the data for single incident in the same way as we did when reading binary incident records the narrative variable is used for two purposesas state indicator and to store the current incident' narrative text if narrative is none it means that we are not currently reading narrativebut if it is string (even an empty oneit means we are in the process of reading narrative lines for linoline in enumerate(fhstart= )line line rstrip(if not line and narrative is nonecontinue if narrative is not noneif line =narrative_end "data["narrative"textwrap dedentnarrativestrip(if len(data! raise incidenterror("missing data on "line { }format(lino)incident incident(**dataself[incident report_idincident data {narrative none elsenarrative +line "\nsince we are reading line by line we can keep track of the current line number and use this to provide more informative error messages than is possible when reading binary files we begin by stripping off any trailing whitespace from