在使用pdb调试python时,如何更改值? [英] How do I change a value while debugging python with pdb?

查看:282
本文介绍了在使用pdb调试python时,如何更改值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行pdb,逐步执行代码,并在某些时候改变一些名称所指向的值。所以我可能想改变名字'stationLat'所指向的值。但似乎我不能。以下是示例:

I want to run pdb, step through the code, and at some point change the value pointed at by some name. So I might want to change the value pointed at by the name 'stationLat'. But it seems I can't. Here's the example:

>>> import extractPercentiles
>>> import pdb
>>> pdb.run( "extractPercentiles.extractOneStation()" )
> <string>(1)<module>()->None
(Pdb) s
--Call--
> /scratch/extractPercentiles.py(96)extractOneStation()
-> def extractOneStation() :
(Pdb) tbreak 132
Breakpoint 3 at /scratch/extractPercentiles.py:132
(Pdb) c

Deleted breakpoint 3
> /scratch/extractPercentiles.py(132)extractOneStation()
-> stationLon = float(stationLoc[3])

所以现在我在一个我想要的地方改变电台的价值。 Pdb似乎允许我将stationLat设置为一个新值,但是当我检查该值时,它不变:

So now I'm at a place where I would like to change the value of stationlat. Pdb appears to allow me to set stationLat to a new value, but when I inspect the value, it is unchanged:

(Pdb) stationLat
-34.171100000000003
(Pdb) stationLat = -40
(Pdb) stationLat   
-34.171100000000003
(Pdb) !stationLat = -40
(Pdb) stationLat
-34.171100000000003
(Pdb) 

你可以看到我试过使用!而且没有成功。

You can see I tried using ! as well, without success.

pdb手册说我应该可以更改变量:

The pdb manual says I should be able to change variables:

甚至可以更改变量 或调用函数

Commands that the debugger doesn’t recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point (!). This is a powerful way to inspect the program being debugged; it is even possible to change a variable or call a function

这是一个范围问题吗?是否与我开始pdb的方式有关?我尝试嵌入的pdb.set_trace成语,我得到了相同的结果。

Is this a question of scope? Is it to do with the way I have started pdb? I tried the embedded "pdb.set_trace" idiom and I got the same result.

感谢您阅读。

推荐答案

在Python 2.6中的href =http://bugs.python.org/issue5215 =noreferrer>错误。你应该可以在Python 2.7中这样做。

This appears to be a bug in Python 2.6. You should be able to do this in Python 2.7.

这篇关于在使用pdb调试python时,如何更改值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆