1

I am using python version 3.7.1 in spyder.

When I run a script and I need to debug I simply enter the line below the line before where an error happens.

breakpoint()

So far for my basic needs this has been sufficient. I can see the current values of the variables or type commands in the ipdb> command line section.

However I can't work out how to use a conditional break point? I have tried reading various sites but don't quite understand what I need to do. They also tend to mention pdb not ipdb. How can I use a conditional break point?

mHelpMe
  • 6,336
  • 24
  • 75
  • 150
  • 1
    Have you tried putting it under an if statement? `if my_condition: breakpoint()` – abdusco Jul 05 '19 at 19:50
  • No I understand that will work but I'm trying to get used to using debugging in python. In other languages it seems a bit easier – mHelpMe Jul 05 '19 at 19:53
  • 1
    Conditional breakpoints are really easy with IDEs but with ipython I'd guess it's harder to implement (or out of project scope), seeing how it's a frontend to the Python console. If you want better control over the flow of your code, you should try PyCharm Community Edition (free for all), or if you're a student you could even use PyCharm Professional for free. – abdusco Jul 05 '19 at 19:58
  • 1
    `pdb` itself has a syntax for this, which you can use in `ipdb`: https://stackoverflow.com/a/55159862/71631 – billc Dec 20 '19 at 23:19

1 Answers1

0

I think @billc's comment above is what OP was looking for. In the console, you enter

b <line number>, <condition to break under>

For example: b C:\Users\powlo\project\tests\TestCase.py:350, view.view_name == 'app.views.export' Example from @powlo

official docs here https://docs.python.org/3/library/pdb.html#pdbcommand-break

JoeyC
  • 764
  • 11
  • 19