pdb怎么调试python,在使用pdb调试python时,如何更改值?

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()" )

> (1)()->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])

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.

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

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.

Thanks for reading.

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值