當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。