-
Notifications
You must be signed in to change notification settings - Fork 121
/
mydir.py
33 lines (28 loc) · 867 Bytes
/
mydir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!python
"""
mydir.py: a module that list the namespaces of other modules
"""
from __future__ import print_function
seplen = 60
sepchr = '-'
def listing(module, verbose=True):
sepline = sepchr * seplen
if verbose:
print(sepline)
print('name:', module.__name__, 'file:', module.__file__)
print(sepline)
count = 0
for attr in sorted(module.__dict__): # Scan namespace keys (or enumerate)
print('%02d) %s' % (count, attr), end=' ')
if attr.startswith('__'):
print('<built-in name>') # Skip __file__, etc
else:
print(getattr(module, attr)) # Same as .__dict__[attr]
count += 1
if verbose:
print(sepline)
print(module.__name__, 'has following %d names' % count)
print(sepline)
if __name__ == '__main__':
import mydir
listing(mydir)