Is there tool out there which can be used to graphically represent the structure of a python module?
I'm thinking that a graph of sub-modules and classes connected 开发者_开发百科by arrows representing imports.
I think you want the Python library snakefood
sfood: Given a set of input files or root directories, generate a list of dependencies between the files;
sfood-graph: Read a list of dependencies and produce a Graphviz dot file. (This file can be run through the Graphviz dot tool to produce a viewable/printable PDF file);
I know this question is very old. If someone is searching a tool for visualising the structure of a Python module, you can try Sourcetrail.
This tool helps you to visualise big source codes such as PyTorch or TensorFlow.
It starts with a nice overview of the project.
If you go inside the Classes button and select any class
, it will show you the connection of a specific class
with other classes and functions.
All the buttons are clickable and gives you a nice overview. This gives you a kickstart to understand the structure of unknown source code very easily.
Not sure if there's a tool, but you could always parse the package you're working with, walking the directory subtree and recording the classes for each module, and also recording the imports. (If you're working with a single module, then it'd just be checking the classes and inputs, no path-walking required.) Then you'd have to iteratively or recursively (Python recommends iteration) check each module imported for anything imported by them until there are no more imports to make (be careful about circular imports!).
You'll probably find pydot
or something similar quite useful for graphically displaying the structure.
An IDE for Python, called ERIC used to have this very functionality
精彩评论