简体   繁体   English

Python 控制台未更新(使用 PyCharm)

[英]Python console doesn't get updated (with PyCharm)

I am new at Python, and I am using PyCharm.我是 Python 新手,正在使用 PyCharm。 I have trying to use the console to interactively check what my functions do, but once the functions have been loaded, they don't get updated.我试图使用控制台以交互方式检查我的函数的作用,但是一旦加载了函数,它们就不会更新。 More precisely :更确切地说 :

Given a set of functions in "functions.py", I write in the the console "from functions import *" This works at first, but when the functions in "functions.py" are changed, the console doesn't see it, even if I relauch the "import" command.给定“functions.py”中的一组函数,我在控制台中写“from functions import *” 这个一开始是有效的,但是当“functions.py”中的函数发生变化时,控制台就看不到了,即使我重新启动“导入”命令。

Any idea of what I shoud do?知道我应该做什么吗?

Thanks谢谢

Reload your module by doing reload(functions) .通过执行reload(functions)重新加载您的模块。

Then do the from functions import * one more time (as you're importing everything).然后再执行一次from functions import * (因为您正在导入所有内容)。

Then it will work.然后它会起作用。

Alternatively, if you're importing just the module:或者,如果您只导入模块:

import functions 

and calling it from the module namespace:并从模块命名空间调用它:

functions.my_function()

then only reload(functions) is sufficient (no need to call import again).那么只有reload(functions)就足够了(不需要再次调用import )。

I've tested all of that on Python 2.7.6 in an interpreter session.我已经在解释器会话中在 Python 2.7.6 上测试了所有这些。

You need to do:你需要做:

reload(functions)

And then:进而:

from functions import myfunc从函数导入 myfunc

Thanks to Nobilis for the correction.感谢 Nobilis 的更正。

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

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