Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/python/inspect-api.py @ 703:a589668768d7
moving python samples in separate files (2)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jun 2021 10:07:12 +0200 |
parents | |
children |
rev | line source |
---|---|
703
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 import inspect |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 import numbers |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 import orthanc |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 # Loop over the members of the "orthanc" module |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 for (name, obj) in inspect.getmembers(orthanc): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 if inspect.isroutine(obj): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 print('Function %s():\n Documentation: %s\n' % (name, inspect.getdoc(obj))) |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 elif inspect.isclass(obj): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 print('Class %s:\n Documentation: %s' % (name, inspect.getdoc(obj))) |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 # Loop over the members of the class |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 for (subname, subobj) in inspect.getmembers(obj): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 if isinstance(subobj, numbers.Number): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 print(' - Enumeration value %s: %s' % (subname, subobj)) |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 elif (not subname.startswith('_') and |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 inspect.ismethoddescriptor(subobj)): |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 print(' - Method %s(): %s' % (subname, inspect.getdoc(subobj))) |
a589668768d7
moving python samples in separate files (2)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 print('') |