Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python3 pdb: how to repeat multiple commands

Tags:

python-3.x

pdb

How do you repeat a multiple commands?

Multiple commands may be entered on a single line, separated by ;;.
[...]
Entering a blank line repeats the last command entered.

I have already tried:

n ;; l
<ENTER>

But only the list command would be repeated.

Sticking with pdb (no ipdb & co), would you know how to repeat effortlessly multiple commands?

Thanks !

like image 943
jbl Avatar asked Sep 03 '25 16:09

jbl


2 Answers

As indicated by @Song, the reason you can't repeat the desired behavior, i.e. stepping rather than showing context, is because the last command in n ;; l is l.

The way I get around this is to use caps for my aliases. Here is what my .pdbrc file looks like:

# Enable completion
import pdb
import rlcompleter
pdb.Pdb.complete=rlcompleter.Completer(locals()).complete

# Show context on startup
l

alias S 'Stepping into...' ;; step ;; l
alias N 'Stepping over...' ;; next ;; l
alias C 'Continuing...' ;; continue ;; l
alias R 'Going to return...' ;; return ;; l

The preceding strings "Stepping into...", etc. let you know when you're executing a custom command versus a native pdb command.

These same commands work for ipdb, too.

like image 170
Lorem Ipsum Avatar answered Sep 05 '25 14:09

Lorem Ipsum


Well, the documentation https://docs.python.org/3/library/pdb.html says

Exception: if the last command was a list command, the next 11 lines are listed.

just right after

Entering a blank line repeats the last command entered

you've mentioned

In your expression

n;;l

as we can see the list command 'l' appears to be the last given command which directly hits the exception

I've faced the same problem and found some sort of a solution - we can simply repeat the last command n;;l by pressing up-arrow key and then enter, just like in terminal. Hope this helps.

like image 32
Song Wukong Avatar answered Sep 05 '25 14:09

Song Wukong