[Python]debug 显示日期时间文件行号

import sys
import datetime
import os


def print_debug_info(o):
    try:
        raise Exception
    except:
        f = sys.exc_info()[2].tb_frame.f_back
    print('%s %s %d %s ' % (str(datetime.datetime.now()), os.path.basename(f.f_code.co_filename), f.f_lineno, f.f_code.co_name),
          end='')
    print(o)

你可能感兴趣的:(python,开发语言)