<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Python Debugging</title>
		<description>The art and adventure of Python debugging</description>
		<link>https://pythondebugging.com</link>
		<atom:link href="https://pythondebugging.com/feed.xml" rel="self" type="application/rss+xml" />
		
			<item>
				<title>Python Debugging Tips</title>
				<description>&lt;p&gt;When it comes to debugging, there’s a lot of choices that you can make. It is hard to give generic advice that always works (other than “Have you tried turning it off and back on?”).&lt;/p&gt;

&lt;p&gt;Here are a few of my favorite Python Debugging tips.&lt;/p&gt;

&lt;h2 id=&quot;make-a-branch&quot;&gt;Make a branch&lt;/h2&gt;
&lt;p&gt;Trust me on this. Even if you never intend to commit the changes back upstream, you will be glad your experiments are contained within their own branch.&lt;/p&gt;

&lt;p&gt;If nothing else, it makes cleanup a lot easier!&lt;/p&gt;

&lt;h2 id=&quot;install-pdb&quot;&gt;Install pdb++&lt;/h2&gt;
&lt;p&gt;Seriously. It makes you life easier if you are on the command line.&lt;/p&gt;

&lt;p&gt;All that pdb++ does is replace the standard pdb module with 100% PURE AWESOMENESS. Here’s what you get when you &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install pdbpp&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A Colorized prompt!&lt;/li&gt;
  &lt;li&gt;tab completion! &lt;em&gt;(perfect for poking around!)&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;It slices! It dices!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, maybe the last one is a little</description>
				<pubDate>Sat, 19 May 2018 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-tips</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-tips</guid>
			</item>
		
			<item>
				<title>Cool debugging with Ice Cream</title>
				<description>&lt;p&gt;I’m a huge fan of dropping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logging.debug()&lt;/code&gt; statements into my code as I debug it. But one problem with that approach is making consistent strings that you can find in your logs. If you are having this pain too, you need to check out &lt;a href=&quot;https://github.com/gruns/icecream&quot;&gt;IceCream&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;show-dont-tell&quot;&gt;Show, don’t tell!&lt;/h1&gt;
&lt;p&gt;This library is a nice and very easy to use wrapper for getting data out to the console. Here’s a quick example of how to use it from their README file:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;icecream&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ic&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span clas</description>
				<pubDate>Sat, 24 Mar 2018 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/cool-debugging-with-ice-cream</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/cool-debugging-with-ice-cream</guid>
			</item>
		
			<item>
				<title>Debug Everywhere!</title>
				<description>&lt;p&gt;Sometimes you just want to get everything debugged and get on with your life.&lt;/p&gt;

&lt;p&gt;But as you start to dig in you find that there’s a million methods and you aren’t sure which one you should start with.&lt;/p&gt;

&lt;p&gt;Well, you are in luck! I recently discovered this cool project that will slam in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import pdb; pdb.set_trace()&lt;/code&gt; at the start of every function in a given module. It is called &lt;a href=&quot;https://github.com/dmytrostriletskyi/pdbe&quot;&gt;pdbe&lt;/a&gt; a.k.a. “PDB Everywhere”/&lt;/p&gt;

&lt;p&gt;This is very useful if you have a problem in a specific area of your app, for example in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;util.py&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Admit it, we all have one (or more) of those lurking in our projects…&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This tool will throw the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set_trace()&lt;/code&gt; in there and let you quickly setup a tripwire to get a debugging session started.&lt;/p&gt;

</description>
				<pubDate>Tue, 27 Feb 2018 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/debug-everywhere-with-pdbe</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/debug-everywhere-with-pdbe</guid>
			</item>
		
			<item>
				<title>Python Debugging Tools</title>
				<description>&lt;p&gt;Python has many debugging tools available to help you get through your code. There are tools for working from the command line, and from IDE’s, and even analysis tools that will help prevent bugs in the first place. Let’s look at a few of the big ones.&lt;/p&gt;

&lt;h2 id=&quot;ides&quot;&gt;IDE’s&lt;/h2&gt;
&lt;p&gt;Integrated Development Environments (IDE) are great for getting up and going on a big project in Python.&lt;/p&gt;

&lt;p&gt;The debugging tools for IDE’s will vary from IDE to IDE, but they all typically have the same features: running the code, setting breakpoints, examining the variables.&lt;/p&gt;

&lt;p&gt;One of the best Python IDE’s today is &lt;a href=&quot;https://www.jetbrains.com/pycharm/?fromMenu&quot;&gt;PyCharm&lt;/a&gt;. The community edition comes with everything you need to get started. There is also an awesome ecosystem of plugins that you can get to help push your Python programming to the next level.&lt;/p&gt;

&lt;p&gt;For a really great overview of how to get up and debugging with PyCharm I highly recommend checking out this short YouTub</description>
				<pubDate>Thu, 15 Feb 2018 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-tools</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-tools</guid>
			</item>
		
			<item>
				<title>Debugging workflow</title>
				<description>&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Rebugger&lt;/strong&gt;: (Noun) Someone who repeatedly commits code that causes a fixed bug to come back to life in the code base.&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;“Hey, where’s Tom? The client is saying the latest build is broken.”&lt;/em&gt;&lt;br /&gt;
&lt;em&gt;“Oh, the &lt;strong&gt;rebugger&lt;/strong&gt; took the day off.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Any good General will tell you that you need a plan before you roll into battle. The same is true with computers, especially when it comes to debugging them. Having a debugging workflow is crucial to getting things done quickly.&lt;/p&gt;

&lt;p&gt;Here is my “battle plan” that I use when I start debugging. Roughly it can be broken down into these three steps: Identify the problem, experiment &amp;amp; research, fix. Let’s dive into specifics.&lt;/p&gt;

&lt;h2 id=&quot;identify-the-problem&quot;&gt;Identify the problem&lt;/h2&gt;
&lt;p&gt;There is a wide gulf between the statements “it doesn’t work” and “it’s broken”. Sometimes people will claim something doesn’t work because it isn’t doing what they expected.</description>
				<pubDate>Mon, 15 Jan 2018 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-workflow</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-workflow</guid>
			</item>
		
			<item>
				<title>Python "Off by one" error</title>
				<description>&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Q: What are the 3 hardest problems in computer science?&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;A: Naming things, and off by one errors.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s take a look at a common off-by-one error that we see in Python all the time. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;range&lt;/code&gt; function is very useful for creating a sequence that can be used in loops. Here’s an example of how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;range&lt;/code&gt; might be used:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://pythondebugging.com/images/range-1.png&quot; alt=&quot;range in action&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We see it counted out 10 things, but it started at 0 instead of 1. In some programming languages this is the norm, but for people coming from other languages this can cause confusion.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;range&lt;/code&gt; function can also start at a specified number, and this is when the off-by-one error really tends to bite people. Recently at work we had to write</description>
				<pubDate>Fri, 15 Dec 2017 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-off-by-one-error-range</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-off-by-one-error-range</guid>
			</item>
		
			<item>
				<title>Debugging Python without an IDE</title>
				<description>&lt;p&gt;One of the best things about ideas are that they bring all of your tools together in one place. But sometimes you need to debug Python code without an IDE (Integrated Development Environment). So what do you do? That’s when the command line tool &lt;a href=&quot;https://docs.python.org/3/library/pdb.html&quot;&gt;pdb&lt;/a&gt; comes in very very handy.&lt;/p&gt;

&lt;p&gt;Pdb is the &lt;a href=&quot;https://python.org&quot;&gt;Python&lt;/a&gt; debugger and is normally a command line based utility. You can use this utility to step through your code, examine variables, and even execute small snippets of Python. I use pdb regularly to debug code on remote servers and in Docker containers. Let’s look at a few of the commands that you can do in pdb to help you debug your Python.&lt;/p&gt;

&lt;h2 id=&quot;basic-commands&quot;&gt;Basic commands&lt;/h2&gt;
&lt;p&gt;Two of the most important commands to know about in pdb are the “l” (lowercase L) command to list out your code at the point that you’re at, and the beat the backtrace command which is “bt”. These two commands will h</description>
				<pubDate>Fri, 08 Dec 2017 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/debugging-python-without-ide</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/debugging-python-without-ide</guid>
			</item>
		
			<item>
				<title>Python Debugging Unit Tests</title>
				<description>&lt;p&gt;Unit tests are a great thing to have in your code base. They allow you to check the health of your code and make sure that as you add things the original functionality stays the same. But what do you do when your unit test break? Let’s look at debugging unit tests in Python.&lt;/p&gt;

&lt;p&gt;A unit test is like any other piece of code. The only difference is the testing framework will tell you when specific parts of the code fail then continue running the rest of the tests. Typically what happens is you will either see all of your test break at once, or only a small individual test for break.&lt;/p&gt;

&lt;h2 id=&quot;all-of-the-test-break-at-once&quot;&gt;All of the test break at once&lt;/h2&gt;
&lt;p&gt;When this happens typically something major has happened in your code base. By “major” this can be something as small as a configuration change, or perhaps a “small refactoring” that has happened that had far-reaching consequences.&lt;/p&gt;

&lt;p&gt;When all the tests break it is best to stop and look at a diff of what has changed s</description>
				<pubDate>Sat, 18 Nov 2017 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-unit-test</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-unit-test</guid>
			</item>
		
			<item>
				<title>Python Debugging With Print Statements</title>
				<description>&lt;p&gt;One of the most basic ways to start debugging python is to use print statements. A Python debug print statement simply puts text out to the console so you can see what’s going on. This is useful for seeing what the values of certain variables, or just seeing where your program is going as an excuse. Let’s look at this in a little bit more detail.&lt;/p&gt;

&lt;h2 id=&quot;whats-the-score&quot;&gt;What’s the score?&lt;/h2&gt;
&lt;p&gt;For me, 99% of the time when I have a Python debug print statement it is because I want to see what value a variable has.&lt;/p&gt;

&lt;p&gt;Thanks to Python’s flexibility, sometimes we don’t always pay attention to the data types we are taking in. Using a debug print statement can tell you if you are looking at the right thing, i.e. are we looking at a list, or a string?&lt;/p&gt;

&lt;p&gt;Also, doing a debug print can be very helpful to look at a field in an object. This is super useful if you have a dependency on a 3rd party API that is failing and you’re not writing the correct value into object.&lt;/p&gt;

&lt;</description>
				<pubDate>Sat, 11 Nov 2017 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-with-print-statements</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-with-print-statements</guid>
			</item>
		
			<item>
				<title>Python Debugging Environment</title>
				<description>&lt;p&gt;As Python developers were very fortunate that our Python debugging environment is built into our language. Pdb is the core tool that one uses when debugging python code, but there are many other nice things you can add to this to help make the job easier.&lt;/p&gt;

&lt;p&gt;When I begin a debugging session I like to set up my local environment to help me get through things as quickly as possible. Here are some of the tools I like to do.&lt;/p&gt;

&lt;h2 id=&quot;common-pdb-commands&quot;&gt;Common pdb commands&lt;/h2&gt;
&lt;p&gt;One very cool feature of pdb is the ability to save aliases and other helper functions commands that you’ve used in the past. There is a file called &lt;a href=&quot;https://docs.python.org/3/library/pdb.html#debugger-commands&quot;&gt;.pdbrc&lt;/a&gt; where you can put your commonly used shortcuts and aliases. This is kind of an advanced feature that is useful if you do a lot of debugging.&lt;/p&gt;

&lt;p&gt;For example, if you want to list out all the values of the attributes in a class, you could create a small function to do thi</description>
				<pubDate>Tue, 07 Nov 2017 00:00:00 +0000</pubDate>
				<link>https://pythondebugging.com/articles/python-debugging-environment</link>
				<guid isPermaLink="true">https://pythondebugging.com/articles/python-debugging-environment</guid>
			</item>
		
	</channel>
</rss>
