How to retrieve a Control Flow Graph for python code?
<p>I would like to dump the Control Flow Graph of a given python code,
similar to the option given by gcc compiler option: -fdump-tree-cfg for c code.</p>

<p>I succeeded getting the AST (Abstract Syntax Trees) of a python code,
but it seams quite complex and hassle to get the Control Flow Graph from AST phase.</p>

<p>Is there an easier way to retrieve directly the Control Flow Graph of a python code? any suggestions?</p>

<p>oh by the way I'm using python3.5</p>

<p>Thank you all!</p>

<p>P.S
I really don't know what kind of interpreter I'm using under the hood,
As far as I know it's CPython (not sure), I don't think it's PyPy(Rpython). 
Any suggestion how can I verify it?</p>

<p>See my <a href="http://stackoverflow.com/a/9989663/120163">SO answer on how to build a control flow graph, using an AST</a>.</p>

<p>The original question asked about CFGs for Java, but the approach is actually pretty generic, and the same approach would work for producing a CFG for Python.</p>

<p>I wouldn't have called this "quite complex"; the basic idea is pretty simple.</p>

python abstract-syntax-tree control-flow-graph