How to return a value from a Python callback in Fortran using F2Py
问题 Consider the following Fortran subroutine, defined in test.f: subroutine test(py_func) use iso_fortran_env, only stdout => output_unit external py_func integer :: a integer :: b a = 12 write(stdout, *) a b = py_func(a) write(stdout, *) b end subroutine Also the following Python code, defined in call_test.py: import test def func(x): return x * 2 test.test(func) Compiled with the following (Intel compiler): python f2py.py -c test.f --fcompiler=intelvem -m test I expect this as output when I