python调试器原理_Python视觉调试器

I know there are a thousand posts on debugging in Python but I can't find what I am looking for....a visual debugger. For example:

one@localhost ~ $ cat duh.py

import pdb

class Coordinate(object):

pdb.set_trace()

def __init__(self, x, y):

self.x = x

self.y = y

def __repr__(self):

return "Coord: " + str(self.__dict__)

def add(a, b):

return Coordinate(a.x + b.x, a.y + b.y)

def sub(a, b):

return Coordinate(a.x - b.x, a.y - b.y)

one = Coordinate(100,200)

two = Coordinate(300,200)

add(one, two)

I want to see the values actually being used. Instead of seeing def __init__(self, x, y): I would like to see def __init__(self, 100, 200):

> /home/one/duh.py(14)()

-> one = Coordinate(100,200)

(Pdb) s

--Call--

> /home/one/duh.py(4)__init__()

-> def __init__(self, x, y):

(Pdb) s

> /home/one/duh.py(5)__init__()

-> self.x = x

(Pdb) s

> /home/one/duh.py(6)__init__()

-> self.y = y

(Pdb) s

--Return--

> /home/one/duh.py(6)__init__()->None

-> self.y = y

I'm totally not used being blind on what is going on inside of the interpreter and really would like to see what is going on in the internals like other scripting language debuggers (like JavaScript step-throughs).

解决方案

That pdb debugging doesn't look like fun. I can see why you don't like it.

Fortunately, there are some visual Python debuggers out there. The two that I use most often are commercial products, but they are both well worth the cost. They are Komodo IDE and IntelliJ IDEA. These are multi-language IDEs that support many other languages in addition to Python. There is also a Python-only version of IDEA called PyCharm.

There's also a great free option, Winpdb. It's easy to use: once you install and open it, use File/Launch and enter the full path to your .py file, and then you can start debugging.

Those products are all multiplatform, but if you're on Windows another free option is Microsoft's Python Tools for Visual Studio. You can install this either into the commercial Visual Studio 2015 or the free Community Edition of Visual Studio 2015.

To give you an idea, here are screenshots of your code from Winpdb, Komodo and IDEA. I stepped into the __init__ function in each:

Don't worry if you don't like the code font I used; that's just my personal setting. And of course in normal use the screen is not so cramped; I made it small to fit in a screenshot.

I highly recommend any of these visual debuggers - it's great to be able to step through your code with a single keystroke and watch the variables change as you go.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值