views:

103

answers:

6

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?

+1  A: 

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

  1. Komodo
  2. Pydev for eclipse
Am
Are you referring to Pydev Code Analysis? This doesn't look graphical to me
David Sykes
+2  A: 

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.

Ash Kim
+1  A: 

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"

pygabriel
+1  A: 

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.

Paul Hankin
Interesting idea, and it could get round the problem raised by pygabriel
David Sykes
+1  A: 

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

EnigmaCurry
A: 

If it's Django you can also do

./manage.py graph_models 

if you are using Django Command Extenstions

Adam Nelson