【问题标题】:How can I get method's "args" argument value in while using ipdb?使用 ipdb 时如何获取方法的“args”参数值?
【发布时间】:2018-01-08 13:18:29
【问题描述】:

ipdb 中使用命令aargs 打印有关为该方法提供的参数的信息。如何获取实际的 args 变量,以便处理提供的数据?

例如当我有代码时:

class A(object):
    def test(*args, **kwargs):
        import ipdb; ipdb.set_trace()


A().test('testing arg')

然后在运行代码后我尝试了:

ipdb> args
args = (<__main__.A object at 0x1007bdf90>, 'testing arg')
kwargs = {}
ipdb> args[0]
args = (<__main__.A object at 0x1007bdf90>, 'testing arg')
kwargs = {}
ipdb>

【问题讨论】:

标签: python debugging ipdb


【解决方案1】:

在您的命令前加上 ! 以禁用 pdb 魔法。

ipdb> !args

【讨论】:

    【解决方案2】:

    我经常设置作为 pdb 魔法一部分的虚拟变量,然后使用它们

    ipdb> aa = args
    

    【讨论】:

      猜你喜欢
      • 2010-10-04
      • 2012-01-02
      • 2017-07-19
      • 1970-01-01
      • 2018-08-06
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      相关资源
      最近更新 更多