def visit_Name(self, node):
    print('Name :', node.id)

def visit_Num(self, node):
    print('Num :', node.__dict__['n'])

def visit_Str(self, node):
    print('Str :', node.s)

def visit_Print(self, node):
    pass
Visiting nodes in a syntax tree with Python ast module