开发者

What options are there for visualising class relationships in a Python program [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We开发者_运维百科 don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 9 months ago.

Improve this question

I am maintaining a Python program, and am struggling to understand the relationships between the various classes. I think it would be helpful to see a diagram of how the classes interact.

What options are there available that might allow me to do this?


Just my 2 cents.

Case tools like Enterprise Architect can generate class diagrams from python code, however for the purpose of understanding I prefer to coarsely model the classes and relationships by hand.

I too use UML when I want to understand new code, to get a coarse overview of the collaborations between classes, and to get a view of inheritance heirachies.

Most IDEs have means to explore the code, but I find small cohesive UML diagrams easier to digest and memorize.

I also find domain models easier to understand when on a class diagram.


If you are seeking IDEs that have that feature, then:

  1. Komodo
  2. Pydev for eclipse


gaphor has a feature to import python module and generate uml class diagrams, anyway it's not so good.

Anyway, code analysis tools on python don't work very well since no one can "predict" which arguments will be passed (or returned) by functions and so on. Most of them "guess" the type passed.

Hoping that python 3 with the "function annotation" can solve this sort of "problem"


Great question! Depending on how hands-on you are, you can consider using the trace module on a run of your code.

python -m trace -T yourprogram.py

Will give you who-called-who information. You can either parse this, or write some code that uses trace programatically to extract your call graph.

Once that's done, a bit of dot hacking, and you've got a diagram. Once you've done this, it'd make a cool blog post about what you did and how it worked out.


Check out epydoc. It's generally thought of as a documentation generator, but check out the (automatically generated) graph in this example:

http://epydoc.sourceforge.net/api/epydoc.apidoc.RoutineDoc-class.html


If it's Django you can also do

./manage.py graph_models 

if you are using Django Command Extenstions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜