gpt4 book ai didi

python - 在ipdb中,如何查询与命令同名的变量?

转载 作者:太空宇宙 更新时间:2023-11-04 02:43:59 60 4
gpt4 key购买 nike

我正在尝试调试函数 quicksort(A, l, r),它有一个名为 l 的局部变量。但是,在 ipdb 中,这也对应于查看当前行周围代码的命令。所以我看到了这样的事情:

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)

然而,在这种情况下,我真正想做的是查看 l 的值。有什么方法可以“转义”默认的 l 命令并查看 l 变量的值吗?

最佳答案

this answer 中的建议,您应该在语句前加上感叹号 !

例如:

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>

关于python - 在ipdb中,如何查询与命令同名的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45678350/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com