How to debug?
Chun-Yang opened this issue · 1 comments
Chun-Yang commented
Thank you for your awesome challenges.
I am new to python, I know there is print
and pdb.set_trace()
.
- Could you tell me where is the printed message?
- And how to make pdb.set_trace() work?
donnemartin commented
Hi Chun-Yang,
To debug just add the following line to the Code cell where you want the debugger to start:
import pdb; pdb.set_trace()
For example, you would add it like this:
def unique_chars_hash(string):
import pdb; pdb.set_trace() # Start debugger when this line is hit
chars_set = set()
for char in string:
if char in chars_set:
return False
else:
chars_set.add(char)
return True
Then run both the Code and Unit Test cells (either through the menu "Cell", or through a shortcut such as [shift + enter] or [control + enter].
This will drop you into the pdb debugger where you can issue commands like the following to l(ist) the source code:
l
or n(ext):
n
For a list of all pdb commands, refer to this link.
-Donne