How do I manipulate a variable whose name conflicts with PDB commands? How do I manipulate a variable whose name conflicts with PDB commands? python python

How do I manipulate a variable whose name conflicts with PDB commands?


Use an exclamation mark ! before a statement to have it run :

python -m pdb test.py> /home/user/test.py(1)<module>()-> print('foo')(Pdb) !n = 77(Pdb) !n77(Pdb) nfoo> /home/user/test.py(2)<module>()-> print('bar')(Pdb)

The docs say:

! statement

Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. [...]


You can use semicolons, so just put something else in front of it:

ipdb> print n2ipdb> n> 145 <some code here>  146  147ipdb> 1; n=41ipdb> print n4


That is not the direct answer to your question, but it may help you: PuDB is a console-based visual interface for PDB which separates commands from variable manipulation by design.