Python 终端修改后调用函数

Python calling functions in terminal after modifying it

我正在使用终端测试我在文件中编写的函数。我的系统是 Ubuntu 16.04 和 Python 2.7。我发现每次更改函数的内容然后从终端再次执行时,似乎都没有应用更改。

我的实际目标是设计函数和 类 用于 Tensorflow 计算,但目前,它应该只是一个关于 Python 的问题。

我的意思是,首先在终端中进入 python 环境并导入文件 import try_function as trf,然后调用 trf.try1() #suppose it prints 'hello world'。在我更改 try1() 使其从终端 trf.try1() 打印 'hello'、运行 之后,它仍然打印 'hello world',即使我尝试 import try_function as trf ] 还是不行。有人能告诉我如何让终端执行最新版本的代码吗?谢谢。

您可能应该使用 reload

另见 this related question