Dec-27-2019, 01:07 PM
(Dec-26-2019, 05:50 PM)Gribouillis Wrote:from collections import namedtuple from pprint import pformat import re import sys TableRecord = namedtuple('TableRecord', ('table_name', 'rows')) def table_data_lines(infile): for lineno, line in enumerate(infile, 1): if line.startswith('END TABLE DATA'): break line = line.strip() if line: yield lineno, line def read_table(table_name, sequence, parsed_file): name = None rows = [] last_row = [] for lineno, line in sequence: if line.startswith('TABLE:'): name = line[6:].strip().strip('"') break continued = line.endswith('_') if continued: line = line[:-1].rstrip() L = re.split(r'(\w+)[=]', line) assert L[0] == '' last_row.extend((L[i], L[i+1].strip()) for i in range(1, len(L), 2)) if not continued: rows.append(last_row) last_row = [] parsed_file.append(TableRecord(table_name, rows)) return nameI get what the table_data_lines is doing but I don't know the things in read_table.
what is the parameter inside (table_name, sequence, parsed_file)?