#!/usr/bin/python3 def parse_fwr (string, widths, start=0): """Parse a fixed-width record. string: the string to parse. widths: a list of record widths. A negative width denotes a field to be skipped. start: optional start index. Returns a list of strings. """ results = [] current_index = start for width in widths: if width > 0: results.append(string[current_index : current_index + width]) current_index += width else: current_index -= width return results