Given the following snippet, I expect captured_string to contain the disp statements from the scipy's fortran L-BFGS-B algorithm. This is not what happens. This leads to my question -- what does fortran's format statement print to when called by python via a .pyf file?
from io import StringIO
from contextlib import redirect_stdout
from scipy.optimize import minimize
def foo(x):
return 1/(x+0.001)**2 + x
string = StringIO()
with redirect_stdout(string):
result = minimize(foo, [100], method='L-BFGS-B', options={'disp': True})
captured_string = string.getvalue()
string.close()
print('this string appears before L-BFGS-B output')
("this string appears before L-BFGS-B output" appears after L-BFGS-B output)
printorwritestatements?