[SciPy-user] optimize.fmin_tnc - how to catch its output?
Stéfan van der Walt
Mon Jul 21 17:56:26 CDT 2008
2008/7/21 Marek Wojciechowski <firstname.lastname@example.org>:
> I tried to catch fmin_tnc output to a file in the following way:
> file = open('messages', 'w')
> stdout = sys.stdout
> stderr = sys.stderr
> sys.stdout = file
> sys.stderr = file
> res = optimize.fmin_tnc(..., messages=1)
> sys.stdout = stdout
> sys.stderr = stderr
> But this does not work. I realized that fmin_tnc calls C routine which
> probably uses its own stdout, stderr. Is there a way to catch its output?
I'm afraid you are right. The quickest way I can think of is to grab
it using standard unix pipes:
python optimise_script.py 2>&1 | cat > out.txt
Otherwise, the C-code will have to be modified. Does anybody know
what the best way is to write to sys.stdout and sys.stderr (not printf
that goes to /dev/stdout) via the Python C API?
More information about the SciPy-user