是否有“编辑并继续"?在 PyCharm 中?像在 Ecli

Is there quot;Edit and Continuequot; in PyCharm? Reload code into running program like in Eclipse / PyDev?(是否有“编辑并继续?在 PyCharm 中?像在 Eclipse/PyDev 中那样将代码重新加载到正在运行的程序中?)

本文介绍了是否有“编辑并继续"?在 PyCharm 中?像在 Eclipse/PyDev 中那样将代码重新加载到正在运行的程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有 Python 开发人员!

Hi all Python developers!

在带有 PyDev 的 Eclipse 中,可以在调试时编辑 Python 文件.保存时,PyDev 调试器会将更新的代码重新加载到正在运行的程序中并使用我的新代码.如何在 JetBrains PyCharm(使用社区版)中做同样的事情?

In Eclipse with PyDev it is possible to edit a Python file while debugging. On save, the PyDev debugger will reload the updated code into the running program and uses my new code. How can I do the same thing in JetBrains PyCharm (using Community Edition)?

当我这样做时,Eclipse/PyDev 会写出这样的输出:

Eclipse / PyDev writes an output like this when I do that:

pydev debugger: Start reloading module: "MyWidget" ... 
pydev debugger: Updated function code: <function close at 0x055F4E70>
pydev debugger: reload finished

我搜索了设置和网络,但找不到任何提示.很高兴有任何想法.谢谢.

I searched settings and web and could not find any hint. Very glad about any idea. Thx.

我发现在 Eclipse/PyDev 中必须处于调试模式才能使用此功能.我在 PyCharm 中测试过,但没有重新加载.

I found out in Eclipse/PyDev one has to be in debug mode to be able to use this feature. I tested in PyCharm, but there was no reload done.

推荐答案

毕竟我为我的问题找到了一个有用且可接受的解决方法.它适用于 PyCharm Community Edition 3.1.2,我认为它也适用于商业版.我使用 Python 2.7.6、带有一个主窗口和 20 多个小部件、选项卡等的 PySide (Qt) 在一个中型项目上进行了测试.请按照以下步骤操作...

After all I found a useful and acceptable workaround for my question. It works in PyCharm Community Edition 3.1.2 and I assume it will do in commercial edition as well. I tested on a mid-scale project using Python 2.7.6, PySide (Qt) with one main window and 20+ widgets, tabs, whatever. Follow these steps...

  1. 在 Python 项目中使用 PyCharm :-)
  2. 在 Debug 模式下执行你的代码(目前没有尝试 Release)
  3. 在程序生命周期内导入的模块中编辑一些代码
  4. 让您的程序暂停.为此,您可以单击暂停"按钮.PyCharms Debug 视图中的按钮,然后是应用程序主窗口中需要执行某些操作的任何位置(例如在选项卡标题上).如果你有一个长时间运行的任务并且没有 UI,你可以在你的程序经常出现的地方放置一个断点.
  5. 在调试"视图中,切换到 控制台 标签.左侧有一个按钮显示命令行.点击这里.
  6. 在控制台中,输入 reload(MyModifiedModule) 如果此调用失败,请输入 import MyModifiedModule 并重试.
  7. 在 PyCharm 中点击简历.
  8. 试试你修复的代码.
  1. Work in PyCharm on a python project :-)
  2. Execute your code in Debug mode (did not tried Release so far)
  3. Edit some code in one your modules imported during the life of your program
  4. Make your program pause. To achieve this, you can click the "Pause" button of in PyCharms Debug view and then any place in your applications main window where it would need to do something (for example on a tab header). If you have a long a running task and no UI, you may place a breakpoint in a place your program often comes by.
  5. In the Debug view, switch to the Console tab. There is a button on the left Show command line. Click this.
  6. In the console, type in reload(MyModifiedModule) if this call fails, write import MyModifiedModule and try again.
  7. Click resume in PyCharm.
  8. Try the code you fixed.

对此有一些限制...它不会修复您的主方法或主窗口中的更改,因为它不会再次创建.在我的测试中,我无法从 Qt 重新加载小部件.但它适用于数据容器或工作者等类.

There are some restrictions on this... It won't fix changes in your main method or main window, cause it won't be created again. In my tests I could not reload widgets from Qt. But it worked for classes like data containers or workers.

当你尝试这个时,愿力量与你同在,并毫不犹豫地添加你的经验.

May the force be with you as you try this and do not hesitate to add your experiences.

这篇关于是否有“编辑并继续"?在 PyCharm 中?像在 Eclipse/PyDev 中那样将代码重新加载到正在运行的程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:是否有“编辑并继续"?在 PyCharm 中?像在 Ecli

基础教程推荐