python-3.x - Python f2py 重新加载更改的模块
问题描述
我是编程新手和python
. 我已经设法使用f2py
将 fortran 模块导入到python
. 但是有一个小问题我无法弄清楚。当我更改 fortran 代码并再次使用f2py
刷新模块时,编译器仍会识别模块的第一个版本。如何强制它刷新模块?我已经阅读了关于 的内容importlib.reload
,但它对我没有任何改变。我指的是python3.7
。
fortran 代码 two.f90 是:
module two
implicit none
contains
subroutine twofunc(x,y)
real,intent(in) :: x
real,intent(out) :: y
y = x*x
end subroutine twofunc
end module
然后我将其更改为:
module two
implicit none
contains
subroutine twofunc(x,y)
real,intent(in) :: x
real,intent(out) :: y
y = x*x*x
end subroutine twofunc
end module.
这只是一个测试代码。然后,我运行了 f2py。然后在 Spyder 中:
import importlib
import two
importlib.reload(one10)
y=two.two.twofunc(4)
print(y)
尽管将代码从 x^2 更改为 x^3,但结果仍然是 16。
解决方案
该reload
命令不适用于所有情况。f2py 模块,可能是因为它们包含已编译的代码,通常无法重新加载。
您需要重新启动内核以迭代扩展模块开发(菜单“控制台”-> 重新启动内核或在控制台选项卡上右键单击 -> 重新启动内核)。
推荐阅读
- javascript - 如何使用 jest 和酶测试异步数据获取反应组件?
- c++ - 有没有办法在 c++ 字符数组中输入所需的字符数
- javascript - 在所有其他承诺之前等待 1 个承诺
- python - 从格式列表生成字符串
- node.js - 角度 8 中的多个 socket.io 连接
- java - 使用 Java Spring Controller 从表单中读取值
- keras - CNN-SVM 模型 - 测试准确性的问题
- javascript - 按钮单击在自单击时有效,而不是自动
- javascript - Safari 中的背景视频是否可以毫无延迟?
- excel - 更新字典中的项目时出现意外行为