how to flatten class trees?

Harry George hgg9140 at seanet.com
Sat Aug 5 11:33:18 EDT 2000


I have a collection of classes with lots of inheritance (so far only
single inheritance; maybe multiple in the future).  It is hard to
remember where a given data member or method is defined.  I want to
print out, for each class, all the data members and where they were
defined.  E.g.:

class A:
   a1=0
   def __init__(self):
      self.sa1=1
   def run(self):
      pass
   def run_a(self)
      pass

class B(A):
   b1=0
   def __init__(self):
      A.__init__(self)
      self.sb1=1
   def run_b(self):
      pass

class C(B):
   a1=2
   c1=0
   def __init__(self):
      B.init__(self)
      self.sa1=2
      self.sc1=1
   def run(self):
      print "hello"
   def again(self):
      pass

Listing:
  
class C
   #---class vars---
   B.b1
   C.a1
   C.c1
   #---instance vars---
   B.sb1
   C.sa1
   C.sc1
   #---methods---
   A.run_a
   B.run_b
   C.run
   C.again

Is there a service/tool/script/module already available to do this?
If not, would you recommend working from __dict__ or from "parser" to
do it?

-- 
Harry George
hgg9140 at seanet.com





More information about the Python-list mailing list