我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pydoc.writedoc()。
def test_htmlpage(self): # html.page does not choke on unicode with test.test_support.temp_cwd(): with captured_stdout() as output: pydoc.writedoc(self.Q) self.assertEqual(output.getvalue(), 'wrote Q.html\n')
def createPyDocs(self, filename, dir): """Create an HTML module documentation using pydoc.""" import pydoc package, module = os.path.split(filename) module = os.path.splitext(module)[0] if package: module = package.replace('/', '.') + '.' + module targetName = '%s/%s.html' % (dir, module) self.printMsg('Creating %s...' % targetName) saveDir = os.getcwd() os.chdir(dir) try: stdout = sys.stdout sys.stdout = StringIO() try: try: pydoc.writedoc(module) except Exception: pass msg = sys.stdout.getvalue() finally: sys.stdout = stdout finally: os.chdir(saveDir) if msg: self.printMsg(msg)