ipdb commands obscured by variables

Question:

When i try to debug this sample script with ipdb:

n = 1
next = 1
print('end')

I can’t execute line 3 because python variables obscure pdb commands:

$ ipdb test.py
> /tmp/test.py(1)<module>()
----> 1 n = 1
      2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(2)<module>()
      1 n = 1
----> 2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(3)<module>()
      1 n = 1
      2 next = 1
----> 3 print('end')

ipdb> next
1
ipdb> n
1
ipdb> !n
1
ipdb> !next
1

How can i proceed further with my code execution when both commands (n/next) aren’t recognized anymore? (Let’s assume s/step are also obscured by variables).

What i tried so far:

  • using ipdb3 instead of ipdb – the same problem (maybe because ipdb is link to ipdb3 in my case :))
  • using pdb – it works! n/next commands move to next line instead of displaying python variables. What’s wrong with my ipdb?
  • !!n alleviates the problem – it runs ipdb version of next. If only I could alias n !!n and then repeatedly use Enter to execute it, the problem would be solved for me. But Enter just displays variable n instead of running alias n (which should resolve into !!n)

I’m using

  • Manjaro Linux 16.10
  • Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
  • ipdb (0.10.1)
  • ipython (5.1.0)
  • ipython-genutils (0.1.0)
  • i don’t have ~/.pdbrc file

EDIT

The issue was fixed by by: https://github.com/ipython/ipython/pull/10050

Asked By: Kossak

||

Answers:

Update in 12/14/2016:

Finally the iPython team decide to revoke this design.


The solution of your problem is use !! statement to force standard behavior.

> /home/v-zit/test.py(1)<module>()
----> 1 n = 1
      2 next = 11
      3 print('end')

ipdb> n
> /home/v-zit/test.py(2)<module>()
      1 n = 1
----> 2 next = 11
      3 print('end')

ipdb> n
1
ipdb> !!n
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb> next
11
ipdb> !!next
end
--Return--
None
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb>

Reference:

https://github.com/ipython/ipython/pull/9449

https://github.com/ipython/ipython/pull/10050

Answered By: Ziya Tang

The solution is to use brackets (variable_name).

For example, if you have one vairable named q, you want to check it out, if you directly input q in the prompt, then the ipdb debugging process will break up.

>>> q

Instead, you should input (q) to ckeck this vairable:

>>> (q)
Answered By: KingLiu
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.