Python Debug
If you want to go further and in deep, there is an alternative with gdb
Useful commands
a
print the argument lsit of the current functionhelp
Example
test.py:
def addition(a, b):
r = a + b
return r
def multiplication(a, b):
breakpoint()
r = a * b
return r
addition(multiplication(2, 2), 1)
go up, down, continue (until next breakpoint if present)
lparment@laptop1426597:~/projects/singular/memorandum$ python3 test.py
> /home/lparment/projects/singular/memorandum/test.py(7)multiplication()
-> r = a * b
(Pdb) u
> /home/lparment/projects/singular/memorandum/test.py(10)<module>()
-> addition(multiplication(2, 2), 1)
(Pdb) d
> /home/lparment/projects/singular/memorandum/test.py(7)multiplication()
-> r = a * b
(Pdb) c
go next step
# go next step
lparment@laptop1426597:~/projects/singular/memorandum$ python3 test.py
> /home/lparment/projects/singular/memorandum/test.py(7)multiplication()
-> r = a * b
(Pdb) n
> /home/lparment/projects/singular/memorandum/test.py(8)multiplication()
-> return r
(Pdb) n
--Return--
> /home/lparment/projects/singular/memorandum/test.py(8)multiplication()->4
-> return r
(Pdb) n
--Call--
> /home/lparment/projects/singular/memorandum/test.py(1)addition()
-> def addition(a, b):
(Pdb) n
> /home/lparment/projects/singular/memorandum/test.py(2)addition()
-> r = a + b
(Pdb) n
add a break
Note: break can be a filename:linenumber or a function
lparment@laptop1426597:~/projects/singular/memorandum$ python3 test.py
> /home/lparment/projects/singular/memorandum/test.py(7)multiplication()
-> r = a * b
(Pdb) tbreak addition
Breakpoint 1 at /home/lparment/projects/singular/memorandum/test.py:1
(Pdb) c
Deleted breakpoint 1 at /home/lparment/projects/singular/memorandum/test.py:1
> /home/lparment/projects/singular/memorandum/test.py(2)addition()
-> r = a + b
(Pdb) a
a = 4
b = 1