[issue12913] Add a debugging howto

Terry J. Reedy report at bugs.python.org
Fri Sep 9 20:57:43 CEST 2011


Terry J. Reedy <tjreedy at udel.edu> added the comment:

If you write 'How to debug Python code' rather than just "How to use pdb", I would start with the use of print statements and binary search. Have short sections on using trace and profile. Very useful would be a list of error messages and possible un-obvious to beginners but common causes. The following example comes up regularly on python-list.

TypeError: 'int' object is not callable
  Look in the previous line to see what you called. If it is a builtin name, perhaps you re-assigned the name to something else. Example:

list = 3
<many lines later>
list(1,2,3)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    list(1,2,3)
TypeError: 'int' object is not callable 

Another one we see occasionally ("Is module x broken?") is something like: user runs script.py

import random
x = random.random()
Traceback...
NameError: name 'random.random' is not defined

Solution: user has a file random.py in the same directory

----------
nosy: +terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12913>
_______________________________________


More information about the Python-bugs-list mailing list