{"id":4089,"date":"2024-01-17T13:33:36","date_gmt":"2024-01-17T05:33:36","guid":{"rendered":"http:\/\/cnliutz.wicp.vip\/?p=4089"},"modified":"2024-01-17T13:33:39","modified_gmt":"2024-01-17T05:33:39","slug":"%e8%b0%83%e8%af%95python%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/xnw60rlg.ipyingshe.net:5347\/?p=4089","title":{"rendered":"\u8c03\u8bd5python\u7a0b\u5e8f\u7684\u65b9\u6cd5"},"content":{"rendered":"\n<p>pdb\u5305<br>Python also includes a debugger to step through code. It is found in a module named pdb. This library is modeled after the gdb library for C. To drop into the debugger at any point in a Python program, insert the code:<\/p>\n\n\n\n<p><strong>import pdb; pdb.set_trace()<\/strong><br>These are two statements here, but I typically type them in a single line separated by a semicolon\u2014that way I can easily remove them with a single keystroke from my editor when I am done debugging. This is also about the only place I use a semicolon in Python code (two statements in a single line).<\/p>\n\n\n\n<p>When this line is executed, it will present a (pdb) prompt, which is similar to the REPL. Code can be evaluated at this prompt and you can inspect objects and variables as well. Also, breakpoints can be set for further inspection.<\/p>\n\n\n\n<p>Below is a table listing useful pdb commands:<\/p>\n\n\n\n<p>Command           Purpose<br>h, help                   List the commands available<br>n, next                   Execute the next line<br>c, cont, continue Continue execution until a breakpoint is hit<br>w, where, bt         Print a stack trace showing where execution is<br>u, up                         Pop up a level in the stack<br>d, down                   Push down a level in the stack<br>l, list                         List source code around current line<\/p>\n\n\n\n<p>IDLE\u8fd0\u884c\u5982\u4ee5\u4e0b\u4ee3\u7801\uff0c\u4f7f\u7528\u547d\u4ee4h,n,c,w,u,d,l\u6765\u8c03\u8bd5\u7a0b\u5e8f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Fibonacci series up to n\r\nimport pdb; pdb.set_trace()\r\ndef fib(n):\r\n    a, b = 0, 1\r\n    while a &lt; n:\r\n        print(a, end=' ')\r\n        a, b = b, a+b\r\n    print()\r\n    \r\nfib(1000)\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>pdb\u5305Python also includes a debugger to s <span class=\"readmore\"><a href=\"http:\/\/xnw60rlg.ipyingshe.net:5347\/?p=4089\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-4089","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4089"}],"version-history":[{"count":1,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4089\/revisions"}],"predecessor-version":[{"id":4090,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/4089\/revisions\/4090"}],"wp:attachment":[{"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4089"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xnw60rlg.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}