How to quickly debug misbehaving script in Python without pdb?

后端 未结 3 1145
感情败类
感情败类 2021-01-29 12:58

There is a high level logic error deep within my Python script, and pdb doesn\'t help to debug it. Is there any other way to see what is being executed after I run

3条回答
  •  自闭症患者
    2021-01-29 13:41

    I would recommend using pdb. You can use

    import pdb
    

    at the top of your script, and then add the line

    pdb.set_trace()
    

    somewhere in the code where you want to trace the problem. When the script gets to that line, you will have an interactive console where you can check variable values, run your own checks, and see what is going on. You can use n to execute the next line, or c to continue to the next occurrence of set_trace(). Full documentation is here: http://docs.python.org/2/library/pdb.html.

    Let me know if you have any specific questions!

提交回复
热议问题