Python pydoc 模块,resolve() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用pydoc.resolve()

项目:vspheretools    作者:devopshq    | 项目源码 | 文件源码
def _writedoc(doc, thing, forceload=0):
    """Write HTML documentation to a file in the current directory.
    """
    try:
        obj, name = pydoc.resolve(thing, forceload)
        page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name))
        fname = os.path.join(doc, name + '.html')
        fd = open(fname, 'w')
        fd.write(page)
        fd.close()
    except (ImportError, pydoc.ErrorDuringImport):
        traceback.print_exc(sys.stderr)
    else:
        return name + '.html'
项目:vspheretools    作者:devopshq    | 项目源码 | 文件源码
def _writeclientdoc(doc, thing, forceload=0):
    """Write HTML documentation to a file in the current directory.
    """
    docmodule = pydoc.HTMLDoc.docmodule
    def strongarm(self, obj, name=None, mod=None, *ignored):
        result = docmodule(self, obj, name, mod, *ignored)

        # Grab all the aliases to pyclasses and create links.
        nonmembers = []
        push = nonmembers.append
        for k,v in inspect.getmembers(obj, inspect.isclass):
            if inspect.getmodule(v) is not obj and getattr(v,'typecode',None) is not None:
                push('<a href="%s.html">%s</a>: pyclass alias<br/>' %(v.__name__,k))

        result += self.bigsection('Aliases', '#ffffff', '#eeaa77', ''.join(nonmembers))
        return result

    pydoc.HTMLDoc.docmodule = strongarm
    try:
        obj, name = pydoc.resolve(thing, forceload)
        page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name))
        name = os.path.join(doc, name + '.html')
        fd = open(name, 'w')
        fd.write(page)
        fd.close()
    except (ImportError, pydoc.ErrorDuringImport), value:
        log.debug(str(value))

    pydoc.HTMLDoc.docmodule = docmodule
项目:sphinx-fakeinv    作者:dahlia    | 项目源码 | 文件源码
def import_string(import_path):
    m, _ = pydoc.resolve(import_path)
    return m