import re class DictMaker: # Mike Meyer's class, actually... """DictMaker objects map from re's (with ID's) to dictionaries. The object is created with the re, and then called with the text to be matched against that pattern. The call returns the resulting dictionary object, or None if the search fails.""" def __init__(my, pattern): "Save the (compiled) pattern that this dictionary maker uses." my.pattern = re.compile(pattern) def __getitem__(my, text): "Return the dictionary associated with parsing text with my pattern" result = my.pattern.search(text) if result: return result.groups() return None