help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling Octave from Python


From: Christoph Dalitz
Subject: Re: calling Octave from Python
Date: Thu, 22 Jul 2004 08:52:45 +0200

> On Wed, 2004-07-21 at 10:16, Benny Wong wrote:
> > 
> > Is there any way I could call octave from a python script? Say if i run 
> > a python script from tcsh. Thank you.
> > 
Use the popen2 function from the os module as in the following example:

        import os
        import string

        # make sure to call ocatve with the "quiet" flag
        [pwrite, pread] = os.popen2("octave -q","w")

        pwrite.write("x = [1,2,3];\n")
        pwrite.write("printf('%f\\n', sum(x));\n")

        # always flush the output to avoid deadlocks
        pwrite.flush()
        result = pread.readline()
        print ("Sum = %f" % string.atof(result))

        pwrite.close()
        pread.close()

Christoph



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]