Reputation: 57391
I'm trying to debug a function quicksort(A, l, r)
which has a local variable called l
. However, in ipdb that also corresponds to a command to view the code around the current line. So I'm seeing something like this:
ipdb> dir()
['A', 'ipdb', 'l', 'r']
ipdb> A
[2, 4, 6, 1, 3, 5, 7, 8]
ipdb> l
14 A[0], A[p] = A[p], A[0]
15
16 def quicksort(A, l, r):
17 # n = len(A)
18 import ipdb; ipdb.set_trace()
---> 19 if len(A) == 1:
20 return
21 else:
22 # choose_pivot(A)
23 q = partition(A, l, r)
24 quicksort(A, l, q-1)
What I actually want to do in this case is to see the value of l
, however. Is there any way to 'escape' the default l
command and see the value of the l
variable?
Upvotes: 5
Views: 1313
Reputation: 51
As suggested in this answer, you should prefix your statement with an exclamation mark !
.
For instance:
ipdb> l
267
268 for i, l in enumerate(self.Q.net.layers):
269
270 import ipdb; ipdb.set_trace()
271
--> 272 w, b = l.get_weights()
273
274 res[f"W_{i}"] = wandb.Histogram(w.flatten(), num_bins=250)
275 res[f"B_{i}"] = wandb.Histogram(b.flatten(), num_bins=250)
276
277 wandb.log(res)
ipdb> !l
<tensorflow.python.keras.layers.core.Dense object at 0x7fc28308e690>
ipdb>
Upvotes: 5
Reputation: 57391
I found that I can simply do p(l)
to see the __repr__
representation (or print(l)
to see the __str__
representation).
Upvotes: 3