Saving Consol outputs in a python script

DFS nospam at dfs.com
Tue May 3 10:32:19 EDT 2016


On 5/3/2016 8:14 AM, drewes.mil at gmail.com wrote:
> Hello, I'm new to python and have a Question.
>
> I'm running a c++ file with a python script like:
>
> import os
> import subprocess
>
> subprocess.call(["~/caffe/build/examples/cpp_classification/classification", "deploy.prototxt", "this.caffemodel", "mean.binaryproto", "labels.txt", "Bild2.jpg"])
>
> and it runes fine. On the console it gives me the output:
>
> ~/Desktop/Downloader/Sym+$ python Run_C.py
> ---------- Prediction for Bild2.jpg ----------
> 0.9753 - "Class 1"
> 0.0247 - "Class 2"
>
>
> What I need are the 2 values for the 2 classes saved in a variable in the .py script, so that I can write them into a text file.
>
> Would be super nice if someone could help me!


This looks like the ticket:

http://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/



> have a nice day!
>
> Steffen





More information about the Python-list mailing list