log.py 文件源码

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

项目:highway.py 作者: PhilipTrauner 项目源码 文件源码
def print_out(message, color, file):
    stack_ = stack()
    # Interestingly the if statement below is not executed when excepting KeyboardInterrupts. Weird.
    # To prevent a crash we assume the module's name is 'Unknown'
    module = "Unknown"
    if getmodule(stack_[2][0]) == None:
        for i in stack_[2:]:
            if getmodule(i[0]) != None:
                try:
                    module = CACHED_MODULES[i[0].f_code]
                except KeyError:
                    module = getmodule(i[0]).__name__
                    CACHED_MODULES[i[0].f_code] = module
    else:
        try:
            module = CACHED_MODULES[stack_[2][0].f_code]
        except KeyError:
            module = getmodule(stack_[2][0]).__name__
            CACHED_MODULES[stack_[2][0].f_code] = module
    print("\033[32m%s\033[0m:%i ? %s%s\033[0m" % (
        module, stack_[2][0].f_lineno, color, 
        message), file=file)
    file.flush()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号