# ast.py -rw-r--r-- 270 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import ast

code = """
foo.bar()
"blah".format()
"""

class Visitor(ast.NodeVisitor):
    def visit_Call(self, node):
        print(ast.dump(node, include_attributes=True))
        self.generic_visit(node)

tree = ast.parse(code)
visitor = Visitor()
visitor.visit(tree)
# output.py -rw-r--r-- 475 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Call(
    func=Attribute(
        value=Name(id='foo', ctx=Load(), lineno=2, col_offset=0), 
        attr='bar',
        ctx=Load(),
        lineno=2,
        col_offset=0
    ), 
    args=[],
    keywords=[],
    lineno=2,
    col_offset=0
)

Call(
    func=Attribute(
        value=Str(s='blah', lineno=3, col_offset=0),
        attr='format',
        ctx=Load(),
        lineno=3,
        col_offset=0
    ),
    args=[],
    keywords=[],
    lineno=3,
    col_offset=0
)