summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2019-07-16 23:00:09 +0530
committerPrabhu Ramachandran2019-07-16 23:00:09 +0530
commit43d3d3a9d741e07abc3d6b178ed9e5c7b55ad7c9 (patch)
tree1cf5101e7c197d49f70d3ae3b57a8287f1725e15
parent5d64412fc50dd3d436448320a607c3fd82644c69 (diff)
downloadpython-workshops-43d3d3a9d741e07abc3d6b178ed9e5c7b55ad7c9.tar.gz
python-workshops-43d3d3a9d741e07abc3d6b178ed9e5c7b55ad7c9.tar.bz2
python-workshops-43d3d3a9d741e07abc3d6b178ed9e5c7b55ad7c9.zip
Added slides on pdb.
-rw-r--r--cbse/data/broken.py27
-rw-r--r--cbse/pdb.ipyml137
2 files changed, 164 insertions, 0 deletions
diff --git a/cbse/data/broken.py b/cbse/data/broken.py
new file mode 100644
index 0000000..2f5278c
--- /dev/null
+++ b/cbse/data/broken.py
@@ -0,0 +1,27 @@
+def count_words(text):
+ result = {}
+ for word in text.lower().split():
+ result[word] += 1
+ return result
+
+
+def test_simple():
+ text = 'one'
+ res = count_words(text)
+ assert res['one'] == 1
+ assert len(res) == 1
+
+
+def test_count_words():
+ # Given
+ text = 'one two Two three THREE three'
+ # When
+ res = count_words(text)
+ # Then
+ assert res['one'] == 1
+ assert res['two'] == 2
+ assert res['three'] == 3
+
+
+if __name__ == '__main__':
+ test_count_words()
diff --git a/cbse/pdb.ipyml b/cbse/pdb.ipyml
new file mode 100644
index 0000000..dc8299f
--- /dev/null
+++ b/cbse/pdb.ipyml
@@ -0,0 +1,137 @@
+cells:
+
+- markdown: |
+ # Debugging with PDB
+
+ - `pdb` is Python's built-in debugger
+ - Available as a standard library
+ - Easy to use
+ - Powerful
+ - https://docs.python.org/3/library/pdb.html
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- markdown: |
+ ## A simple but broken script
+
+ - Let us first study the script
+ - Some useful programming principles
+
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- code: |
+ %load data/broken.py
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- markdown: |
+ ## Debugging from IPython
+
+ - Easy to get started
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- code: |
+ %cd data
+
+- code: |
+ import broken
+
+- code: |
+ broken.test_simple()
+
+- code: |
+ %debug
+
+- markdown: |
+ ## `pdb` commands
+
+ - `h(elp) [command]`
+ - `p expression`
+ - `s(tep)`
+ - `n(ext)`
+ - `q(uit)`
+ - `l(ist) [first[, last]]`
+ - `c(ontinue)`
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- markdown: |
+ ## More pdb commands
+
+ - `w(here)`
+ - `d(own) [count]`
+ - `u(p) [count]`
+ - `b(reak) [([filename:]lineno | function) [, condition]]`
+ - `tbreak`
+ - `pp expression`
+ - `cl(ear) [filename:lineno | bpnumber [bpnumber ...]]`
+ - `condition bpnumber [condition]`
+ - `display [expression]`
+ - `interact`
+ - `run [args]`
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+
+- code: |
+ # Turn on auto-pdb
+ %pdb
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- code: |
+ %run -d script.py
+
+- code: |
+ %run -d -b20 script.py
+
+- markdown: |
+ ## Debugging from the console
+
+ - Allows one to debug a script
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- code: |
+ # Run this on a shell
+ !python -m pdb broken.py
+
+
+- markdown: |
+ ## Adding a manual breakpoint in code
+
+ Handy when writing code and you want to inspect at that point.
+
+ metadata:
+ slideshow:
+ slide_type: slide
+
+- code: |
+ import pdb; pdb.set_trace()
+
+- markdown: |
+ ## More information
+
+ - See https://docs.python.org/3/library/pdb.html
+
+ metadata:
+ slideshow:
+ slide_type: slide