到目前为止,我得到的结论是:def make_pdoc():
import pdoc
import sys
from os import path, makedirs
libpath = 'C:\\path\\to\\file\\'
if path.exists(libpath):
sys.path.append(libpath)
pdoc.import_path.append(libpath)
mod = pdoc.import_module('package-name-here')
doc = pdoc.Module(mod, allsubmodules=True)
string = doc.html(external_links=True)
# Package level
with open(doc.name + '/_doc/index.html', 'w') as html_file:
html_file.write(string.encode('utf-8'))
# Sublevel 1
for submodule in doc.submodules():
string = submodule.html(external_links=True)
if submodule.is_package():
exte = '/index.html'
else:
exte = '.m.html'
dpath = (submodule.name.split('.')[0] + '/_doc/' +
submodule.name.split('.')[-1]) + '/'
if not path.exists(dpath):
makedirs(dpath)
with open(dpath + exte, 'w') as html_file:
html_file.write(string.encode('utf-8'))
# Sublevel 2
if submodule.submodules():
for subsubmodule in submodule.submodules():
print subsubmodule.name
string = subsubmodule.html(external_links=True)
if subsubmodule.is_package():
exte = '.html'
else:
exte = '.m.html'
with open(subsubmodule.name.split('.')[0] + '/_doc/' +
subsubmodule.name.split('.')[1] + '/' +
subsubmodule.name.split('.')[-1] +
exte, 'w') as html_file:
html_file.write(string.encode('utf-8'))
if __name__ == '__main__':
make_pdoc()
这段代码根据源包中的树结构在html页面中创建目录。在