June 2017
Beginner
352 pages
8h 39m
English
Since we know the problem lies in digits(), let's set an explicit breakpoint in there using the pdb.set_trace() function mentioned earlier:
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] """ import pdb; pdb.set_trace() digs = [] while x != 0: div, mod = divmod(x, 10) digs.append(mod) x = mod return digs
Remember that the set_trace() function will halt execution and enter the debugger.
So now we can just execute our script without specifying the PDB module:
% python palindrome.py> /Users/sixty_north/examples/palindrome.py(8)digits()-> digs = [](Pdb)
And we see that we almost ...
Read now
Unlock full access