当前的pdb.set_trace()调用是在定义类时进行的,而不是在调用init之后。如果将pdb.set_trace()调用移到init中import pdb
class Coordinate(object):
def __init__(self, x, y):
pdb.set_trace()
self.x = x
self.y = y
def __repr__(self):
return "Coord: " + str(self.__dict__)
def add(a, b):
return Coordinate(a.x + b.x, a.y + b.y)
def sub(a, b):
return Coordinate(a.x - b.x, a.y - b.y)
one = Coordinate(100,200)
two = Coordinate(300,200)
add(one, two)
然后在pdb中输入print x, y并获取值:C:\Users\randlet>python duh.py
> c:\users\randlet\duh.py(6)__init__()
-> self.x = x
(Pdb) print x, y
100 200
(Pdb) c
> c:\users\randlet\duh.py(6)__init__()
-> self.x = x
(Pdb) print x, y
300 200
(Pdb) n
> c:\users\randlet\duh.py(7)__init__()
-> self.y = y
(Pdb) n
--Return--
> c:\users\randlet\duh.py(7)__init__()->None
-> self.y = y
(Pdb) n
> c:\users\randlet\duh.py(18)()
-> add(one, two)
(Pdb) print one, two
Coord: {'y': 200, 'x': 100} Coord: {'y': 200, 'x': 300}
(Pdb) s
--Call--
> c:\users\randlet\duh.py(10)add()
-> def add(a, b):
(Pdb) print a, b
Coord: {'y': 200, 'x': 100} Coord: {'y': 200, 'x': 300}
(Pdb)