code: def iterparse(source, encoding='utf-8'):
      
      if hasattr(source, 'read'):
          for event in _parse2(source):
              yield event
      else:
          with io.open(source, encoding=encoding) as fh:
              for event in _parse2(fh):
                  yield event
docs: Parse the TDL file *source* and iteratively yield parse events.
  
      If *source* is a filename, the file is opened and closed when the
      generator has finished, otherwise *source* is an open file object
      and will not be closed when the generator has finished.
  
      Parse events are `(event, object, lineno)` tuples, where `event`
      is a string (`"TypeDefinition"`, `"TypeAddendum"`,
      `"LexicalRuleDefinition"`, `"LetterSet"`, `"WildCard"`,
      `"LineComment"`, or `"BlockComment"`), `object` is the interpreted
      TDL object, and `lineno` is the line number where the entity began
      in *source*.
  
      Args:
          source (str, file): a filename or open file object
          encoding (str): the encoding of the file (default: `"utf-8"`;
              ignored if *source* is an open file)
      Yields:
          `(event, object, lineno)` tuples
      Example:
          >>> lex = {}
          >>> for event, obj, lineno in tdl.iterparse('erg/lexicon.tdl'):
          ...     if event == 'TypeDefinition':
          ...         lex[obj.identifier] = obj
          ... 
          >>> lex['eucalyptus_n1']['SYNSEM.LKEYS.KEYREL.PRED']
          <String object (_eucalyptus_n_1_rel) at 140625748595960>