def nodeChunk(lines):
    """
    Parse NODE Method
    """
    # Constants
    KEYWORDS = ('NODE',
                'X_Y',
                'ELEV')

    result = {'node': None,
              'x': None,
              'y': None,
              'elev': None}

    chunks = pt.chunk(KEYWORDS, lines)

    # Parse chunks associated with each key
    for key, chunkList in iteritems(chunks):
        # Parse each chunk in the chunk list
        for chunk in chunkList:
            schunk = chunk[0].strip().split()
            if key == 'X_Y':
                result['x'] = schunk[1]
                result['y'] = schunk[2]
            else:
                result[key.lower()] = schunk[1]

    return result
def nodeChunk ( lines ) : KEYWORDS = ( 'NODE' , 'X_Y' , 'ELEV' ) result = { 'node' : None , 'x' : None , 'y' : None , 'elev' : None } chunks = pt . chunk ( KEYWORDS , lines ) for key , chunkList in iteritems ( chunks ) : for chunk in chunkList : schunk = chunk [ 0 ] . strip ( ) . split ( ) if key == 'X_Y' : result [ 'x' ] = schunk [ 1 ] result [ 'y' ] = schunk [ 2 ] else : result [ key . lower ( ) ] = schunk [ 1 ] return result
Parse NODE Method