def printDebug(self, tree, head): f = XMLOutput(open('temp.html', 'w')) f.begin('ul') def printNode(f, node): if not isinstance(node, tuple): f.begin('li') f.write(str(node)) f.begin('ul') children = tree.get(node, ()) for child in children: printNode(f, child) if not isinstance(node, tuple): f.end('ul') f.end('li') printNode(f, head) f.end('ul') f.close()