def main(args): parser = optparse.OptionParser(usage="astvisualizer.py [options] [string]") parser.add_option("-f", "--file", action="store", help="Read a code snippet from the specified file") parser.add_option("-l", "--label", action="store", help="The label for the visualization") options, args = parser.parse_args(args) if options.file: with open(options.file) as instream: code = instream.read() label = options.file elif len(args) == 2: code = args[1] label = "" else: print("Expecting Python code on stdin...") code = sys.stdin.read() label = "" if options.label: label = options.label code_ast = ast.parse(code) transformed_ast = transform_ast(code_ast) renderer = GraphRenderer() renderer.render(transformed_ast, label=label)