1

Say inside test_fortran_module.f90 there is defined a subroutine

subroutine sum2numbers(x, y, z)
  implicit none
  real, intent(in) :: x, y
  real, intent(out) :: z

  write (*, *) 'z = x + y'
  z = x + y
end subroutine sum2numbers

and I compile it using f2py:

f2py3 -c test_fortran_module.f90 -m test_fortran_module

Inside IPython (the interactive prompt),

In [26]: import test_fortran_module

In [27]: z = test_fortran_module.sum2numbers(7, 6)
 z = x + y

it is seen that 'z = x + y' is printed. But if the same thing is done in a IPython notebook,

enter image description here

'z = x + y' is not printed. Is there a way to do it?

Thomas K
  • 39,200
  • 7
  • 84
  • 86
qAp
  • 1,139
  • 2
  • 12
  • 26
  • 2
    Possible duplicate of http://stackoverflow.com/questions/35584787/the-stdout-stderr-in-python-notebooks , but now answer there, just some links and hints, which could be made into an answer with some effort. – Vladimir F Героям слава Jun 02 '16 at 09:16
  • We (Jupyter) are now working on a proposal that would let us capture output at the OS level, which would fix this. In the meantime, the links and hints on the previous question can be hammered into something to do it, at least on Unix systems. – Thomas K Jun 02 '16 at 15:56
  • 1
    @ThomasK: `os.dup2()` should work on Windows too. Though [I haven't tested it personally](http://stackoverflow.com/a/22434262/4279) – jfs Jun 02 '16 at 16:17
  • @ThomasK: this seems to be working in the notebook by now. But is there also a version that doesn't only flush all output only at the end? – John Smith May 11 '23 at 10:07

0 Answers0