demoClassesInMaxPlus.py

demoClassesInMaxPlus.py
1 '''
2  Demonstrates using the inspect module to list all of the classes in the
3  MaxPlus API and the total number of members exposed.
4 '''
5 
6 import MaxPlus, os, inspect
7 
8 api = {}
9 classes = inspect.getmembers(MaxPlus, inspect.isclass)
10 totalcnt = 0
11 for c in classes:
12  name = str(c[0])
13  membercnt = len(c[1].__dict__)
14  totalcnt += membercnt
15  api[name] = membercnt
16 
17 fname = os.path.join(MaxPlus.PathManager.GetTempDir(), 'maxplus_api.txt')
18 with open(fname, 'w') as f:
19  for k in sorted(api.keys()):
20  f.write(k + " has " + str(api[k]) + " members\n")
21 
22 print "Results saved to", fname
23 print "Total number of classes ", len(api)
24 print "Total number of API elements ", totalcnt
25 print "Average number of API elements per class ", totalcnt / len(api)
26