Python debugging: get filename and line number from which a function is called?

前端 未结 4 1913
误落风尘
误落风尘 2020-12-24 01:12

I\'m currently building quite a complex system in Python, and when I\'m debugging I often put simple print statements in several scripts. To keep an overview I often also wa

4条回答
  •  一个人的身影
    2020-12-24 01:46

    Discovered this question for a somewhat related problem, but I wanted more details re: the execution (and I didn't want to install an entire call graph package).

    If you want more detailed information, you can retrieve a full traceback with the standard library module traceback, and either stash the stack object (a list of tuples) with traceback.extract_stack() or print it out with traceback.print_stack(). This was more suitable for my needs, hope it helps someone else!

提交回复
热议问题