What is the breakpoint function for

Asked

Viewed 172 times

3

I’m digging myself in python, and as a good curious beginner I am researching the functions already present in the python without the use of any library, when I come across the function breakpoint(). I don’t really understand what its function is in itself, since the language of the official website is very formal and I still don’t have the wit to understand some terms...

1 answer

3


The built-in function breakpoint() calls the Python Interactive Source Code Debugger.
This debugger features:

  • Support the definition of conditional and single-pass interruption points at source.
  • Inspection of stack frame.
  • Source code listing.
  • Arbitrary Python code evaluation in the context of any stack frame.

Running the example:

a = "teste"
breakpoint()
print(a)

When the interpreter finds the function breakpoint() command line will switch to the shell of the interactive Python source debugger (Pdb)

> /home/runner/2608v0dh5c5/main.py(3)<module>()
-> print(a)
(Pdb) ▉

To know the list of available commands type on this command line h or help:

> /home/runner/2608v0dh5c5/main.py(3)<module>()
-> print(a)
(Pdb) help

Documented commands (type help <topic>):
========================================
EOF    c          d        h         list      q        rv       undisplay
a      cl         debug    help      ll        quit     s        unt      
alias  clear      disable  ignore    longlist  r        source   until    
args   commands   display  interact  n         restart  step     up       
b      condition  down     j         next      return   tbreak   w        
break  cont       enable   jump      p         retval   u        whatis   
bt     continue   exit     l         pp        run      unalias  where    

Miscellaneous help topics:
==========================
exec  pdb

(Pdb) ▉

To get a description of a specific command type help <nome_do_comando>:

(Pdb) help next
n(ext)
        Continue execution until the next line in the current function
        is reached or it returns.
(Pdb) ▉

The elementary commands are:

  • p expressão : Evaluates the expression expression in the current context and prints its value. Example:
(Pdb) p a
'teste'
(Pdb) ▉
(Pdb) whatis a
<class 'str'>
(Pdb) ▉
(Pdb) !a = "não é mais um teste"
(Pdb) p a
'não é mais um teste'
(Pdb) ▉
  • next : Continue execution until the next line in the current function is reached or it returns. Example:
(Pdb) next
não é mais um teste
--Return--
> /home/runner/2608v0dh5c5/main.py(3)<module>()->None
-> print(a)
(Pdb) ▉

A full description of the commands available in the Python interactive source debugger is available in the online documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.