Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fe904d

Browse files
committed
Use string methods; minor code cleanup.
1 parent 0cf4269 commit 4fe904d

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

Doc/tools/custlib.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,54 @@
22

33
# Phase I: list all the things that can be imported
44

5-
import glob, os, sys, string
6-
modules={}
5+
import glob
6+
import os.path
7+
import sys
8+
9+
modules = {}
710

811
for modname in sys.builtin_module_names:
9-
modules[modname]=modname
12+
modules[modname] = modname
1013

1114
for dir in sys.path:
1215
# Look for *.py files
13-
filelist=glob.glob(os.path.join(dir, '*.py'))
16+
filelist = glob.glob(os.path.join(dir, '*.py'))
1417
for file in filelist:
1518
path, file = os.path.split(file)
16-
base, ext=os.path.splitext(file)
17-
modules[string.lower(base)]=base
19+
base, ext = os.path.splitext(file)
20+
modules[base.lower()] = base
1821

1922
# Look for shared library files
20-
filelist=(glob.glob(os.path.join(dir, '*.so')) +
21-
glob.glob(os.path.join(dir, '*.sl')) +
22-
glob.glob(os.path.join(dir, '*.o')) )
23+
filelist = (glob.glob(os.path.join(dir, '*.so')) +
24+
glob.glob(os.path.join(dir, '*.sl')) +
25+
glob.glob(os.path.join(dir, '*.o')) )
2326
for file in filelist:
2427
path, file = os.path.split(file)
25-
base, ext=os.path.splitext(file)
26-
if base[-6:]=='module': base=base[:-6]
27-
modules[string.lower(base)]=base
28+
base, ext = os.path.splitext(file)
29+
if base[-6:] == 'module':
30+
base = base[:-6]
31+
modules[base.lower()] = base
2832

2933
# Minor oddity: the types module is documented in libtypes2.tex
3034
if modules.has_key('types'):
31-
del modules['types'] ; modules['types2']=None
35+
del modules['types']
36+
modules['types2'] = None
3237

3338
# Phase II: find all documentation files (lib*.tex)
3439
# and eliminate modules that don't have one.
3540

36-
docs={}
37-
filelist=glob.glob('lib*.tex')
41+
docs = {}
42+
filelist = glob.glob('lib*.tex')
3843
for file in filelist:
39-
modname=file[3:-4]
40-
docs[modname]=modname
44+
modname = file[3:-4]
45+
docs[modname] = modname
4146

42-
mlist=modules.keys()
43-
mlist=filter(lambda x, docs=docs: docs.has_key(x), mlist)
47+
mlist = modules.keys()
48+
mlist = filter(lambda x, docs=docs: docs.has_key(x), mlist)
4449
mlist.sort()
45-
mlist=map(lambda x, docs=docs: docs[x], mlist)
50+
mlist = map(lambda x, docs=docs: docs[x], mlist)
4651

47-
modules=mlist
52+
modules = mlist
4853

4954
# Phase III: write custlib.tex
5055

0 commit comments

Comments
 (0)