finallythe textnode state very simply extracts the text before the next close tag and sets it as value on the current nodeclass textnodedef process(selfremaining_stringparser)i_start_tag remaining_string find('<'text remaining_string[:i_start_tagparser current_node text text parser state childnode(return remaining_string[i_start_tag:now we just have to set up the initial state on the parser object we created the initial state is firsttag objectso just add the following to the __init__ methodself state firsttag(to test the classlet' add main script that opens an file from the command lineparses itand prints the nodesif __name__ ="__main__"import sys with open(sys argv[ ]as filecontents file read( parser(contentsp start(nodes [ rootwhile nodesnode nodes pop( print(nodenodes node children nodes this code opens the fileloads the contentsand parses the result then it prints each node and its children in order the __str__ method we originally added on the node class takes care of formatting the nodes for printing if we run the script on the earlier exampleit outputs the tree as followsbook authordusty phillips publisherpackt publishing titlepython object oriented programming content number