__init__.py 文件源码

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

项目:napalm-logs 作者: napalm-automation 项目源码 文件源码
def cast(var, function):
    # If the function is a build in function
    if locate(function) and hasattr(locate(function), '__call__'):
        try:
            return locate(function)(var)
        except ValueError:
            log.error('Unable to use function %s on value %s', function, var, exc_info=True)
    # If the function is str function
    if hasattr(str, function) and\
            hasattr(getattr(str, function), '__call__'):
        return getattr(str, function)(var)
    glob = globals()
    # If the function is defined in this module
    if function in glob and hasattr(glob[function], '__call__'):
        return glob[function](var)
    # If none of the above, just return the original var
    return var
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号