As Edward says, adding a call to pdb.set_trace() works. This assumes you
already know where to put the breakpoint. If you don't, then one way is
just start pdb before any code executes and start stepping through the
code. Usually this is tiresome because you end up stepping through a lot of
code and you don't know which code you should step over vs. step into. The
command for this is:

python -m pdb <thescript>


I find it is usually better to use the python trace module to get a feel
for the flow of the code. From that output you may be able figure out where
you want to set a breakpoint:

python -m trace --trace <thescript>


But this has way too much output so it is better to filter out all the
standard python library calls. Do that by running this command to get this
list of directories to ignore:

python -c 'import sys ; print(":".join(sys.path)[1:])'


And run your trace command like this:

python -m trace --trace --ignore-dir <output from above command> <thescript>


This requries <thescript> to be located outside your standard library paths
(i.e. installed with pip), otherwise the execution trace of that code will
be excluded as well.


On Mon, Aug 12, 2019 at 6:03 AM Edward K. Ream <[email protected]> wrote:

> On Sun, Aug 11, 2019 at 7:29 PM Matt Wilkie <[email protected]> wrote:
>
> I figured I'd buckle down and learn how to use a debugger properly like
>> the Smart Kids Do.
>>
>
> Insert calls to g.pdb().  This will start Python's pdb debugger
> <https://docs.python.org/3/library/pdb.html>. You must be running Leo
> from a console.
>
> When you hit a breakpoint, hit "n" once to move out of the Leo code and
> into the code you want to see.
>
> If "g" isn't available, then start the debugger using:
>
> import pdb ; pdb.set_trace()
>
> Imo, there is seldom a need for anything other than pdb.  Guido has said
> that's what he uses.
>
> Edward
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/leo-editor/CAMF8tS0AvV5nUw3Q9-4iEW_c2tRaCVsvkRFRb8azO%3DOZ5cw%2BrQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/leo-editor/CAMF8tS0AvV5nUw3Q9-4iEW_c2tRaCVsvkRFRb8azO%3DOZ5cw%2BrQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAO5X8Cy1h4681fxfHXxRbOR49NeA4zD3NmBLh2o4fAkw3HDtgA%40mail.gmail.com.

Reply via email to