pythonipdb

In ipdb, how to query a variable which as the same name as a command?


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?


Solution

  • I found that I can simply do p(l) to see the __repr__ representation (or print(l) to see the __str__ representation).