In [1]:
%install_ext https://raw.github.com/rocky/ipython-trepan/master/trepanmagic.py
Installed trepanmagic.py. To use it, type:
%load_ext trepanmagic
In [2]:
%load_ext trepanmagic
trepanmagic.py loaded
In [3]:
%trepan /tmp/gcd.py 3 5
(/tmp/gcd.py:10): <module>
-> 10 """
(trepan3k) set autolist on
(trepan3k) next
(/tmp/gcd.py:11): <module>
-- 11 import sys
6
7 check_args() raises an uncaught exception when given the wrong number
8 of parameters.
9
10 """
11 -> import sys
12
13 def check_args():
14 if len(sys.argv) != 3:
15 # Rather than use sys.exit let's just raise an error
(trepan3k) next
(/tmp/gcd.py:40): <module>
-- 40 if __name__=='__main__':
35 return None
36 if a == 1 or b-a == 0:
37 return a
38 return gcd(b-a, a)
39
40 -> if __name__=='__main__':
41 check_args()
42
43 (a, b) = sys.argv[1:3]
44 print("The GCD of %d and %d is %d" % (a, b, gcd(a, b)))
(trepan3k) eval?
eval: __name__=='__main__'
Out[3]:
True
(trepan3k) break gcd
Breakpoint 1 set on calling function gcd()
Currently this is line 26 of file /tmp/gcd.py
(trepan3k) continue
(/tmp/gcd.py:26): gcd
xx 26 def gcd(a,b):
21 print("** Expecting an integer, got: %s" % repr(sys.argv[i]))
22 sys.exit(2)
23 pass
24 pass
25
26 B-> def gcd(a,b):
27 """ GCD. We assume positive numbers"""
28
29 # Make: a <= b
30 if a > b:
(trepan3k) backtrace
->0 gcd(a=3, b=5) called from file '/tmp/gcd.py' at line 26
##1 <module> exec()
'/tmp/gcd.py' at line 44
(trepan3k) continue
(/tmp/gcd.py:26): gcd
xx 26 def gcd(a,b):
21 print("** Expecting an integer, got: %s" % repr(sys.argv[i]))
22 sys.exit(2)
23 pass
24 pass
25
26 B-> def gcd(a,b):
27 """ GCD. We assume positive numbers"""
28
29 # Make: a <= b
30 if a > b:
(trepan3k) backtrace
->0 gcd(a=2, b=3) called from file '/tmp/gcd.py' at line 26
##1 gcd(a=3, b=5) called from file '/tmp/gcd.py' at line 38
##2 <module> exec()
'/tmp/gcd.py' at line 44
(trepan3k) delete 1
Deleted breakpoint 1
(trepan3k) continue
(/tmp/gcd.py:26): gcd
xx 26 def gcd(a,b):
21 print("** Expecting an integer, got: %s" % repr(sys.argv[i]))
22 sys.exit(2)
23 pass
24 pass
25
26 -> def gcd(a,b):
27 """ GCD. We assume positive numbers"""
28
29 # Make: a <= b
30 if a > b:
(trepan3k) continue
The GCD of 3 and 5 is 1
The program finished - quit or restart
(/tmp/gcd.py:37): gcd
xx 37 return a
32 pass
33
34 if a <= 0:
35 return None
36 if a == 1 or b-a == 0:
37 -> return a
38 return gcd(b-a, a)
39
40 if __name__=='__main__':
41 check_args()
(trepan3k) quit
In [ ]:
Content source: rocky/ipython-trepan
Similar notebooks: