[Python-il] debugging Python

Amit Aronovitch aronovitch at gmail.com
Fri Jan 22 17:18:04 IST 2010


On Thu, Jan 21, 2010 at 6:58 PM, Yitzhak Wiener <Yitzhak.Wiener at dspg.com>wrote:

>  Hi Dear People,
>
>
>
> As really beginner in Python, I face many problems and find it relatively
> difficult to study Python only threw the documentation.
>
In case you did not try that yet, using an interactive interpreter is
tremendous help for testing out new ideas and especially when learning new
stuff.

IDE's come with their own interactive prompts, but you always have the
included python shell (just type "python" at the command line), as described
in most tutorials. You get immediate feedback on errors, and in case of
error inside a function, use post mortem debugger ("import pdb; pdb.pm()").
Useful tip if you use this option on a Unix:
put the following line in an auto-startup file (environment variable
PYTHONSTARTUP points to your auto-startup file):

import readline,rlcompleter; readline.parse_and_bind("tab: complete")

this will give your shell bash-like history mechanism, and completion which
is aware not only of python syntax, but also of the current contents of your
variables (think accessing members of class instances).

Even easier solution - use ipython: has colors, improved history and much
much more. See following link for demo of using pdb in ipython (basically
saves you the effort of typing pdb.pm() )
http://www.wonderhowto.com/how-to/video/how-to-debug-python-using-the-ipython-shell-7289/

I find myself writing small python script with many errors, and find it hard
> to understand the error reason only from command line error message.
>
>
As I said - testing with interactive interpreter is great for that (you can
do anything - loops, call any function you think of, examine (print, change,
manipulate) variables, and get immediate response. For traceback and
examining local vars of failed functions, pdb.pm() should work.

>
>
> Is there a better way to write python scripts? I used regular editor but it
> doesn’t know the functions and syntax of Python. What is the best
> development area for Python? Is there some kind of debugger for Python?
>
>
>
IDE's also have graphic debuggers (probably built as wrappers around pdb).
Do not have much experience with the python IDE's mentioned in previous
posts. IDLE (the "standard" tk IDE included with python) has some debugging
support - single stepping and jumping through source files work nicely, but
last time I checked (long time ago) running programs with debug mode on in
IDLE is quite slow and tends to get it stuck.

>
>
> Best Regards,
>
> Yitzhak
>

  Best,
       AA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://hamakor.org.il/pipermail/python-il/attachments/20100122/92de43b6/attachment.htm 


More information about the Python-il mailing list