Let's say I've already imported a python module in the interpreter. How can I get the abstract syntax tree of the imported module (and any functions and classes within it) within the interpreter? I don't want to have to re-parse the source files. Thanks!
Maybe you find some inspiration in this recipe:
A function that outputs a human-readable version of a Python AST.
Or use compiler
combined with inspect
(which, of course, still uses the source):
>>> import compiler, inspect
>>> import re # for testing
>>> compiler.parse(inspect.getsource(re))
Module('Support for regular expressions (RE). \n\nThis module provides ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With