当前位置: 首页>>代码示例>>Python>>正文


Python pydoc.ErrorDuringImport方法代码示例

本文整理汇总了Python中pydoc.ErrorDuringImport方法的典型用法代码示例。如果您正苦于以下问题:Python pydoc.ErrorDuringImport方法的具体用法?Python pydoc.ErrorDuringImport怎么用?Python pydoc.ErrorDuringImport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydoc的用法示例。


在下文中一共展示了pydoc.ErrorDuringImport方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: convert_string_to_type

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import ErrorDuringImport [as 别名]
def convert_string_to_type(string_value):
    """Converts a string into a type or class

    :param string_value: the string to be converted, e.g. "int"
    :return: The type derived from string_value, e.g. int
    """
    # If the parameter is already a type, return it
    if string_value in ['None', type(None).__name__]:
        return type(None)
    if isinstance(string_value, type) or isclass(string_value):
        return string_value

    # Get object associated with string
    # First check whether we are having a built in type (int, str, etc)
    if sys.version_info >= (3,):
        import builtins as builtins23
    else:
        import __builtin__ as builtins23
    if hasattr(builtins23, string_value):
        obj = getattr(builtins23, string_value)
        if type(obj) is type:
            return obj
    # If not, try to locate the module
    try:
        obj = locate(string_value)
    except ErrorDuringImport as e:
        raise ValueError("Unknown type '{0}'".format(e))

    # Check whether object is a type
    if type(obj) is type:
        return locate(string_value)

    # Check whether object is a class
    if isclass(obj):
        return obj

    # Raise error if none is the case
    raise ValueError("Unknown type '{0}'".format(string_value)) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:40,代码来源:type_helpers.py

示例2: generatedocs

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import ErrorDuringImport [as 别名]
def generatedocs(module, filename):
    try:
        sys.path.insert(0, os.getcwd() + '/..')
        # Attempt import
        mod = pydoc.safeimport(module)
        if mod is None:
           print("Module not found")

        # Module imported correctly, let's create the docs
        with open(filename, 'w') as f:
            f.write(getmarkdown(mod))
    except pydoc.ErrorDuringImport as e:
        print("Error while trying to import " + module)

# if __name__ == '__main__': 
开发者ID:tock,项目名称:tockloader,代码行数:17,代码来源:generate_docs.py

示例3: main

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import ErrorDuringImport [as 别名]
def main(argv=None):
        parser = ArgumentParser()
        parser.add_argument('function')
        parser.add_argument('args', nargs=REMAINDER)
        args = parser.parse_args(argv)
        try:
            func = pydoc.locate(args.function)
        except pydoc.ErrorDuringImport as exc:
            raise exc.value from None
        if func is None:
            raise ImportError('Failed to locate {!r}'.format(args.function))
        argparse_kwargs = (
            {'prog': ' '.join(sys.argv[:2])} if argv is None else {})
        retval = run(func, argv=args.args, argparse_kwargs=argparse_kwargs)
        sys.displayhook(retval) 
开发者ID:anntzer,项目名称:defopt,代码行数:17,代码来源:defopt.py

示例4: generatedocs

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import ErrorDuringImport [as 别名]
def generatedocs(module):
    try:
        sys.path.append(os.getcwd())
        # Attempt import
        mod = pydoc.safeimport(module)
        if mod is None:
           print("Module not found")
        # Module imported correctly, let's create the docs
        return getmarkdown(mod)
    except pydoc.ErrorDuringImport as e:
        print("Error while trying to import " + module) 
开发者ID:RedisJSON,项目名称:redisjson-py,代码行数:13,代码来源:gendoc.py

示例5: generatedocs

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import ErrorDuringImport [as 别名]
def generatedocs(module):
    try:
        sys.path.append(os.getcwd())
        # Attempt import
        mod = pydoc.safeimport(module)
        if mod is None:
           print("Module not found")
        
        # Module imported correctly, let's create the docs
        return getmarkdown(mod)
    except pydoc.ErrorDuringImport as e:
        print("Error while trying to import " + module) 
开发者ID:RediSearch,项目名称:redisearch-py,代码行数:14,代码来源:gendoc.py


注:本文中的pydoc.ErrorDuringImport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。