3

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

12
  • Using pdb3 your example works as expected. Repeated next steps through the program and restarts it while !next shows the value of the variable. Can't reproduce in cpython's pdb. Commented Oct 24, 2016 at 17:38
  • I installed python3-ipdb on my linux machine and it worked there also. next was always treated as a command and !next showed the value of the variable. Commented Oct 24, 2016 at 17:44
  • I added versions of my python/ipdb/ipython to my post. Maybe it makes difference. Commented Oct 24, 2016 at 17:46
  • 1
    !!n should force it to run the command instead of showing the variable. I think !n forces it to treat it as a variable, and n guesses. Commented Oct 25, 2016 at 10:28
  • 1
    I have created a pull request to fix the empty line problem you face. github.com/ipython/ipython/pull/10035 Commented Oct 25, 2016 at 22:52

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I don't think del n is a workaround - it destroys python variable that the program is using, so it will crash upon reading it.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.