Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108063 > unrolled thread

Saving Consol outputs in a python script

Started bydrewes.mil@gmail.com
First post2016-05-03 05:14 -0700
Last post2016-05-03 12:50 -0400
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Saving Consol outputs in a python script drewes.mil@gmail.com - 2016-05-03 05:14 -0700
    Re: Saving Consol outputs in a python script DFS <nospam@dfs.com> - 2016-05-03 10:32 -0400
    Re: Saving Consol outputs in a python script Stephen Hansen <me+python@ixokai.io> - 2016-05-03 08:43 -0700
    Re: Saving Consol outputs in a python script Terry Reedy <tjreedy@udel.edu> - 2016-05-03 12:50 -0400

#108063 — Saving Consol outputs in a python script

Fromdrewes.mil@gmail.com
Date2016-05-03 05:14 -0700
SubjectSaving Consol outputs in a python script
Message-ID<b188eaaf-7945-4f40-9cfc-f56dd3f34407@googlegroups.com>
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!


have a nice day!

Steffen

[toc] | [next] | [standalone]


#108072

FromDFS <nospam@dfs.com>
Date2016-05-03 10:32 -0400
Message-ID<ngacj3$6po$1@dont-email.me>
In reply to#108063
On 5/3/2016 8:14 AM, drewes.mil@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

[toc] | [prev] | [next] | [standalone]


#108078

FromStephen Hansen <me+python@ixokai.io>
Date2016-05-03 08:43 -0700
Message-ID<mailman.348.1462290243.32212.python-list@python.org>
In reply to#108063
On Tue, May 3, 2016, at 05:14 AM, drewes.mil@gmail.com wrote:
> 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!

You shouldn't use the call() convienence function, but instead create a
process using the Popen constructor, passing PIPE to stdout. Then use
communicate() to get the output.

This should get you started:

    process = subprocess.Popen(["commandline"], stdout=subprocess.PIPE)
    output, error = process.communicate()

Output will be a string, string has a splitlines method, etc.

-- 
Stephen Hansen
  m e @ i x o k a i . i o

[toc] | [prev] | [next] | [standalone]


#108083

FromTerry Reedy <tjreedy@udel.edu>
Date2016-05-03 12:50 -0400
Message-ID<mailman.351.1462294241.32212.python-list@python.org>
In reply to#108063
On 5/3/2016 8:14 AM, drewes.mil@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.

pycaffe is a python interface to caffe.  You should look into it and 
probably use it.  Its functions will return python objects.  I suspect 
that is has a function that will return the result of calling the caffe 
classification function

Stackoverflow has question/answers tagged with 'caffe' and 'pycaffe'.
(There is also a caffe-users group on google groups.)

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web