Windows下使用Notepad++和IDLE编译模块

2024-06-09 06:12:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的模块和一个基本的def。模块名为example315.py,def为

def right_justify(s)
    print(s)

当我导入example315,然后调用example315.right\u justify(“hello world”)时,这种方法很好地工作

如果我把def改为不返回任何东西(事实上我可以以任何方式更改它),然后再次运行函数(当然在保存了我的模块之后),iit仍然会打印。在

如果不把它闲置起来重新开始,我似乎无法使它运转起来。在

有什么帮助吗


Tags: 模块方法函数pyrighthelloworlddef
2条回答

每个会话加载一次模块,更改时必须重新加载。在

Python tutorial on modules

For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use reload(), e.g. reload(modulename).

您面临的问题是IDLE已经导入并构建了模块的内部表示。在磁盘上编辑文件不会反映到现在导入的内存驻留版本处于空闲状态。你应该能够得到你想要的行为:

example315 = reload(example315)

这里有一些来源:Python Docs Source

相关问题 更多 >