【问题标题】:How to get contents of a variable in IPython REPL when debugging?调试时如何在 IPython REPL 中获取变量的内容?
【发布时间】:2019-10-01 11:14:54
【问题描述】:

我将 python 3 与 Spyder 一起使用。考虑以下代码:

def fun(x,y):
    n,m = len(x), len(y)
    pass #set breakpoint on this line

x = [1,2,3]
y = [1,2,3]

fun(x,y)

当我在第三行设置断点并运行调试器时,我希望能够在调试器控制台中评估 nm。键入m(然后回车)按预期返回一个数字,键入n 只显示打印调试器的当前状态。我假设n 是一些特殊的调试器命令。

  • 在哪里可以找到所有可以在调试器控制台中使用的命令?
  • 如何仍能打印与其中一些命令同名的变量?

【问题讨论】:

    标签: python-3.x debugging ipython spyder


    【解决方案1】:

    您可以在 python 文档中找到这些命令:https://docs.python.org/3.7/library/pdb.html

    命令p <expression>可用于评估和打印python表达式,因此在这种情况下您必须使用p n来获取n的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-03
      • 2020-08-14
      • 2019-06-17
      • 1970-01-01
      • 2011-03-16
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多