utils.py 文件源码

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

项目:argparseinator 作者: ellethee 项目源码 文件源码
def check_class():
    """
    Return the class name for the current frame.
    If the result is ** None ** means that the call is made from a module.
    """
    # get frames
    frames = inspect.stack()
    cls = None
    # should be the third frame
    # 0: this function
    # 1: function/decorator
    # 2: class that contains the function
    if len(frames) > 2:
        frame = frames[2][0]
        if '__module__' in frame.f_code.co_names:
            cls = SillyClass(**frame.f_locals)
            cls.__cls_name__ = frame.f_code.co_name
    return cls
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号