<story><title>Debugging Python Like a Boss</title><url>https://zapier.com/engineering/debugging-python-boss</url></story><parent_chain></parent_chain><comment><author>haberman</author><text>Debuggers are cool and often necessary, but I disagree with this often-expressed sentiment that print-debugging is a primitive hack for people who don&amp;#x27;t know any better.&lt;p&gt;Debugging is determining the point at which the program&amp;#x27;s &lt;i&gt;expected&lt;/i&gt; behavior diverges from its &lt;i&gt;actual&lt;/i&gt; behavior.  You often don&amp;#x27;t know where where&amp;#x2F;when this is happening.  Print-debugging can give you a transcript of the program&amp;#x27;s execution, which you can look at to hone in on the moment where things go wrong.  Stepping through a program&amp;#x27;s execution line-by-line and checking your assumptions can be a lot slower in some cases.  And most debuggers can&amp;#x27;t go backwards, so if you miss the critical moment you have to start all over again.&lt;p&gt;These are two tools in the toolbox; using print debugging does not mean you are not &amp;quot;a boss.&amp;quot;</text></comment>
<story><title>Debugging Python Like a Boss</title><url>https://zapier.com/engineering/debugging-python-boss</url></story><parent_chain></parent_chain><comment><author>hcarvalhoalves</author><text>A good list of libraries, but please, don&amp;#x27;t use this in the middle of your code to set a break point:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    import pdb; pdb.set_trace();
&lt;/code&gt;&lt;/pre&gt;
There&amp;#x27;s a chance you forget this, check-in, and it ends in production. Use pdb facilities instead:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    $ python -m pdb &amp;lt;myscript&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
Then set a breakpoint and continue:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    (Pdb) break &amp;lt;filename.py&amp;gt;:&amp;lt;line&amp;gt;
    (Pdb) c
&lt;/code&gt;&lt;/pre&gt;
This is trivial to automate from any editor or command line, so you don&amp;#x27;t even have to guess the path to the file.&lt;p&gt;EDIT: For the lazy, here&amp;#x27;s a script to set breakpoints from the command line and run your scripts:&lt;p&gt;&lt;a href=&quot;https://gist.github.com/hcarvalhoalves/7587621&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;gist.github.com&amp;#x2F;hcarvalhoalves&amp;#x2F;7587621&lt;/a&gt;</text></comment>