kdllib.py 文件源码

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

项目:crikey 作者: kastnerkyle 项目源码 文件源码
def get_generic_name():
    # may need to make this a search for the first non-kdllib reference
    # make generic name from highest calling context
    prev_function_name = None
    for i in range(len(inspect.stack())):
        (frame, filename, line_number,
         function_name, lines, index) = inspect.stack()[i]
        #print(frame, filename, line_number, function_name, lines, index)
        # Use stack to get easier function name than parsing the code itself
        if i > 0:
            _, _, _, prev_function_name, _, _ = inspect.stack()[i - 1]
        else:
            prev_function_name = function_name
        script_name = filename.split(os.sep)[-1]
        lib_location = os.path.realpath(__file__)
        lib_name = lib_location.split(os.sep)[-1]
        # cover .py and .pyc
        if script_name != lib_name and script_name != lib_name[:-1]:
            name = script_name + "_" + prev_function_name
            #print(frame, filename, line_number, function_name, lines, index)
            return name
    raise ValueError("Issue in generic name getter")


# Many of these from Ishaan G.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号