Python视觉调试器 [英] Python Visual Debugger

查看:119
本文介绍了Python视觉调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有上千篇有关使用Python进行调试的文章,但我找不到我想要的...视觉调试器。例如:

  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(ax + bx,ay + by)
def sub(a,b):
返回坐标(ax-bx,ay-by)

一个=坐标(100,200)
两个=坐标(300,200)

add(一个,两个)

我想查看实际使用的值。而不是看到 def __init __(self,x,y):我想看到 def __init __(self,100,200):

 > /home/one/duh.py(14)< module>()
->一个=坐标(100,200)
(Pdb)s
-呼叫-
> /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
-返回-
> /home/one/duh.py(6)__init__()->无
-> self.y = y

我完全不习惯对内部发生的事情视而不见解释器,真的很想像其他脚本语言调试器(例如JavaScript逐步调试器)一样查看内部情况。

解决方案

pdb调试看起来并不有趣。我明白了为什么你不喜欢它。



幸运的是,那里有一些可视化的Python调试器。我最常使用的两种是商业产品,但是它们都值得花费。它们是 Komodo IDE IntelliJ IDEA 。这些是多语言IDE,除了Python外还支持许多其他语言。还有一个名为 PyCharm 的纯Python版本。



还有一个很棒的免费选项, Winpdb 。它易于使用:安装并打开它后,使用文件/启动并输入 .py 文件的完整路径,然后就可以开始调试了。



这些产品都是多平台的,但是如果您在Windows上,另一个免费的选择是Microsoft的用于Visual Studio的Python工具。您可以将其安装到商业Visual Studio 2015或免费的Visual Studio 2015社区版中。 ,Komodo和IDEA。我分别进入了 __ init __ 函数:




 




 





如果您不喜欢我使用的代码字体,请不要担心;那只是我的个人设定。当然,在正常使用中,屏幕也不是那么狭窄。我把它缩小到了适合截图的大小。



我强烈建议您使用这些可视化调试器中的任何一个-能够通过一次简单的按键操作就可以观看代码,这非常好变量随您而变化。


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)<module>()
-> 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.

这篇关于Python视觉调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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