demoClassesInMaxPlus.py
Main Page
Modules
Classes
Examples
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
7
import
os
8
import
inspect
9
10
api = {}
11
classes = inspect.getmembers(MaxPlus, inspect.isclass)
12
totalcnt = 0
13
for
c
in
classes:
14
name = str(c[0])
15
membercnt = len(c[1].__dict__)
16
totalcnt += membercnt
17
api[name] = membercnt
18
19
fname = os.path.join(
MaxPlus.PathManager.GetTempDir
(),
'maxplus_api.txt'
)
20
with open(fname,
'w'
)
as
f:
21
for
k
in
sorted(api.keys()):
22
f.write(k +
" has "
+ str(api[k]) +
" members\n"
)
23
24
print
"Results saved to"
, fname
25
print
"Total number of classes "
, len(api)
26
print
"Total number of API elements "
, totalcnt
27
print
"Average number of API elements per class "
, totalcnt / len(api)