Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用pdb调试Python_Python_Python 2.7_Pdb - Fatal编程技术网

使用pdb调试Python

使用pdb调试Python,python,python-2.7,pdb,Python,Python 2.7,Pdb,我正在尝试使用pdb调试python代码。我有一个名为c的变量,当我按c打印这个变量时,pdb会感到困惑,并继续调试到下一个断点。考虑到更改变量名称非常困难,我如何避免这种混淆。您可以告诉pdb不要使用来评估类似的内容前缀: >>> !c ... <value of c> >>!C ... 要打印变量,请使用p p c 将打印变量c的值 e、 g: 导入pdb >>>c=[1,2,3] >>>pdb.set_trace() --返回-- >(1)无 (Pd

我正在尝试使用pdb调试python代码。我有一个名为c的变量,当我按c打印这个变量时,pdb会感到困惑,并继续调试到下一个断点。考虑到更改变量名称非常困难,我如何避免这种混淆。

您可以告诉pdb不要使用
来评估类似的内容前缀:

 >>> !c
 ... <value of c>
>>!C
... 

要打印变量,请使用
p

p c
将打印变量
c的值

e、 g:

导入pdb >>>c=[1,2,3] >>>pdb.set_trace() --返回-- >(1)无 (Pdb)p c [1, 2, 3]
您的困惑在于PDB中的各种命令的作用。我觉得它有点像一个非常有效的方法:

使用p打印变量的内容(或pp打印(或处理角色的基本需要)):

键入wherew查看您在堆栈上的位置:

(Pdb) w
-> return df[df['type']=='dev'][['Dist','Count']].as_matrix()
  /home/user/core/ops.py(603)wrapper()
-> res = na_op(values, other)
> /home/user/core/ops.py(567)na_op()
-> raise TypeError("invalid type comparison")
看到那个小箭头了吗?这就是我们在堆栈中的位置

使用listl环顾四周:

(Pdb) list
564               try:
565                   result = getattr(x, name)(y)
566                   if result is NotImplemented:
567  >>                     raise TypeError("invalid type comparison")
568               except (AttributeError):
569  ->                 result = op(x, y)
570   
571           return result
572   
573       def wrapper(self, other):
574           if isinstance(other, pd.Series):
要在堆栈中移动,请继续涂泥并使用向上(u)或向下(d

使用argsa)检查调用当前函数的参数:

(Pdb) args
dat = array([], shape=(0, 3), dtype=float64)
dev_classes = {81, 82, 21, 22, 23, 24, 31}

使用交互在堆栈中的当前点输入代码Ctrl+D将您带回PDB。

另请参见:
print
pp
pprint
对此类名称的赋值命令非常有用:
(PDB)!c=某物
(Pdb) list
564               try:
565                   result = getattr(x, name)(y)
566                   if result is NotImplemented:
567  >>                     raise TypeError("invalid type comparison")
568               except (AttributeError):
569  ->                 result = op(x, y)
570   
571           return result
572   
573       def wrapper(self, other):
574           if isinstance(other, pd.Series):
(Pdb) args
dat = array([], shape=(0, 3), dtype=float64)
dev_classes = {81, 82, 21, 22, 23, 24, 31}