python try异常处理之traceback准确定位哪一行出问题

except 有时不能准确的定位出哪一行出现问题,可以用traceback准确定位哪一行出问题

import traceback


def func1():
    raise NameError("--func1 exception--")


def main():
    try:
        func1()
    except Exception as e:
        print(e)
        print(traceback.print_exc())  # 准确定位哪一行出问题


if __name__ == '__main__':
    main()
原文地址:https://www.cnblogs.com/zhaoyingjie/p/14326771.html