简体   繁体   English

Python 调试:即时代码编辑

[英]Python Debugging: code editing on the fly

I am new to python and haven't been able to find out whether this is possible or not.我是 python 的新手,无法确定这是否可行。

I am using the PyDev plugin under Eclipse, and basically all I want to find out is, is it possible to edit code whilst you're sitting at a breakpoint?我在 Eclipse 下使用 PyDev 插件,基本上我想知道的是,是否可以在断点处编辑代码? Ie Edit code whilst you're debugging.即在调试时编辑代码。

It allows me to do this at present, but it seems to still be executing the line of code that previously existed before I made changes.它目前允许我这样做,但它似乎仍在执行我进行更改之前先前存在的代码行。

Also, are you able to drag program execution back like you can in VBA and C# for example?此外,您是否能够像在 VBA 和 C# 中那样将程序执行拖回?

If either of these are possible, how can I enable them?如果其中任何一个都是可能的,我该如何启用它们?

PyDev 从 1.4.8 版开始在一定程度上支持这一点,请参阅更改说明和相应的博客条目

When you start a Python program, it will be compiled into bytecode (and possibly saved as .pyc file).当你启动一个 Python 程序时,它会被编译成字节码(并可能保存为.pyc文件)。 That means you can change the source but since you don't "open" the source again, the change won't be picked up.这意味着您可以更改源,但由于您不会再次“打开”源,因此不会选择更改。

There are systems like TurboGears (a web framework) which detect these changes and restart themselves but that's probably going to confuse the debugger.有像 TurboGears(一个 Web 框架)这样的系统可以检测这些更改并自行重新启动,但这可能会使调试器感到困惑。

Going back in time also isn't possible currently since the bytecode interpreter would need support for this.回到过去目前也是不可能的,因为字节码解释器需要对此提供支持。

You can run arbitrary commands in the console during the breakpoint.您可以在断点期间在控制台中运行任意命令。 For my needs, this typically achieves the same purpose as coding live, although I do wish it were as elegant as simply using the editor.根据我的需要,这通常与实时编码实现相同的目的,尽管我确实希望它像简单地使用编辑器一样优雅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM