def extractdata(pattern, text=None, filepath=None):
y = []<EOL>if text is None:<EOL><INDENT>textsource = open(filepath, '<STR_LIT:r>')<EOL><DEDENT>else:<EOL><INDENT>textsource = text.splitlines()<EOL><DEDENT>for line in textsource:<EOL><INDENT>match = scanf(pattern, line)<EOL>if match:<EOL><INDENT>if len(y) == <NUM_LIT:0>:<EOL><INDENT>y = [[s] for s in match]<EOL><DEDENT>else:<EOL><INDENT>for i, ydata in enumerate(y):<EOL><INDENT>ydata.append(match[i])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if text is None:<EOL><INDENT>textsource.close()<EOL><DEDENT>return y<EOL>
Read through an entire file or body of text one line at a time. Parse each line that matches the supplied
pattern string and ignore the rest.

If *text* is supplied, it will be parsed according to the *pattern* string.
If *text* is not supplied, the file at *filepath* will be opened and parsed.