cli.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:squishy 作者: tmehlinger 项目源码 文件源码
def import_callable(ctx, param, value):
    if value is None:
        return None

    delim = ':'
    if delim not in value:
        raise click.BadParameter(
            'string to import should have the form '
            'pkg.module:callable_attribute')

    mod, identifier = value.rsplit(delim, 1)

    try:
        func_or_cls = getattr(importlib.import_module(mod), identifier)
    except AttributeError:
        raise click.BadParameter('{} does not exist in {}'
                                 .format(identifier, mod))

    if callable(func_or_cls):
        return func_or_cls
    raise RuntimeError('{} is not callable'.format(value))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号