Fixing the bug

After you're out of PDB, let's remove the set_trace() call and modify digits() to fix the problem we found:

def digits(x):
"""Convert an integer into a list of digits.

Args:
x: The number whose digits we want.

Returns: A list of the digits, in order, of ``x``.

>>> digits(4586378)
[4, 5, 8, 6, 3, 7, 8]
"""

digs = []
while x != 0:
div, mod = divmod(x, 10)
digs.append(mod)
x = div
return digs

If we run our program now, we see that we're passing all tests, and it runs very quickly:

$ python palindrome.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK

So that's a basic PDB session, and it demonstrates some of the core features of PDB. PDB has many other commands and features, however, and the best way to learn them is to simply start using PDB and trying out the commands. This palindrome program can serve as a good example for learning most of the features of PDB.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset