python如何升级模块_导入到python解释器时更新模块

In short

How to force python interpreter to load the most up-to-date code version of my module everytime I make some changes in the module code?

Or at least reload the last modified version by typing

>>> from myModule import *

into console, without necessity to restart whole python console and setup everything again and again anytime I make some changes? This is extremely unpleasant behavior for debugging.

--------- LONGER STORY -----------

I tried to delete the .pyc file, and import it again - but it has no effect. It does't even create .pyc file again - so I expect it completely ignore my "import" command if the module is already loaded.

this also does not help:

>>> mymodule.myfunc() # the old version

>>> del myModule # unload mymodle from python conole / interpeter

... # now I removed .pyc

... # now I make some modifications in mymodule.myfunc() code

>>> mymodule.myfunc() # module is unknonwn, ... OK

>>> import myModule # try to load modified version

>>> mymodule.myfunc() # stil the old version :(((((, How it can remember?

I have tried also Spyder where is this feature called "User Module Deleter (UMD)"

http://pythonhosted.org/spyder/console.html#reloading-modules-the-user-module-deleter-umd

which I thought should do exactly this, but it seem it doesn't (Yes, I checked that it is turned on).

Maybe I'm missing something - can somebody explain me how is it supposed to be used?

Is this somehow affected by the fact that the imported module is not in "Working directory" but in PYTHONPATH ?

解决方案

(Spyder dev here) I think at the moment you are not able to reload a module directly in the console (but we are considering to change this in the future).

The idea about UMD is that it will reload your modules but only if you run a file from the editor that imports them. It doesn't work if you want to reload them directly in the console.

Let's say you developed a module, then you are probably using it in a different script that (most likely) you'll be writing in our editor and send it to run to our console. UMD is a little bit of magic that reloads it for you when that happens.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值