Python Forum
Is there a keyword that's equivalent to breakpoint for debugging?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a keyword that's equivalent to breakpoint for debugging?
#1
Hello Pythonians,

I came from MATLAB background. In MATLAB, there is a keyword which is "keyboard" which you type it down anywhere in your code to work exactly like breakpoint. The good thing about it is that even if you close your project and open it again, the code will keep your debugging locations. i.e., wherever "keyboard" is found. It's very handy keyword.

I'm wondering if there is an equivalent keyword for debugging in Python?

Thank you,
Reply
#2
there is pdb: https://docs.python.org/3/library/pdb.html

It has to be imported into the program you're debugging.
Most IDE's have built in debugger as well.
Reply
#3
(Feb-14-2018, 11:29 AM)Larz60+ Wrote: there is pdb: https://docs.python.org/3/library/pdb.html

It has to be imported into the program you're debugging.
Most IDE's have built in debugger as well.

Thank you so much for your prompt and active response.
I feel that pdb make things complicated. Even its documentation is not clear, I could not rally understand it.

So let me ask you this: From your experience, if you are using IDE lie PyCharm, do you really need this pdb library? or the built-in debugging tools in the IDE would be enough?

Because, I'm quite happy with the debugging tool in PyCharm, the only missing thing is the "keyboard" that I was used to it.

Again, thank you....
Reply
#4
Quote:if you are using IDE lie PyCharm, do you really need this pdb library
check out this image:
   
Just click in the left margin to set breakpoint.
lower right window are watches, you can type variable names here, or even code, and it will show their values as you step through the program

The blue arrows are for (in order:
step to next line (single step)
step to next line executed
step to next line executed (but ignore libraries)
step into routine (subroutine for example)using any filters setup
step to first line executed after returning from method
run to line where cursor is located.

It works very well, and I use it all the time.

A trick I use in iterators is to set a counter to zero before entering the loop,
incrementing at the end of each iteration, and then placing some code like:
if counter == 21:
    print('breakpoint here')
and setting the breakpoing to the print statement
you can do the same using the value of a programming variable like account number for example.
Reply
#5
I'm getting confused, there are two threads on same subject that should be merged here
Reply
#6
(Feb-16-2018, 11:15 AM)Larz60+ Wrote: check out this image:
   
Just click in the left margin to set breakpoint.
lower right window are watches, you can type variable names here, or even code, and it will show their values as you step through the program

The blue arrows are for (in order:
step to next line (single step)
step to next line executed
step to next line executed (but ignore libraries)
step into routine (subroutine for example)using any filters setup
step to first line executed after returning from method
run to line where cursor is located.

It works very well, and I use it all the time.

A trick I use in iterators is to set a counter to zero before entering the loop,
incrementing at the end of each iteration, and then placing some code like:
Python Code: (Double-click to select all)
1
2
if counter == 21:
    print('breakpoint here')
and setting the breakpoing to the print statement
you can do the same using the value of a programming variable like account number for example.


Thank you so much, you are always helpful.

(Feb-16-2018, 11:17 AM)Larz60+ Wrote: I'm getting confused, there are two threads on same subject that should be merged here

It's really up to you, whatever you see is alright with me.

Regards,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 746 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  pydev error pydev debugger: warning: trying to add breakpoint to file that does not e kwhhst 8 9,045 Jun-15-2019, 02:52 PM
Last Post: kwhhst
  equivalent commands saeed_balk 2 2,612 Sep-23-2018, 05:44 AM
Last Post: saeed_balk
  gdb breakpoint in python module Viesturs 0 2,179 Jul-27-2018, 02:02 PM
Last Post: Viesturs

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020