[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling Octave from Python
From: |
Stefan van der Walt |
Subject: |
Re: Calling Octave from Python |
Date: |
Mon, 16 Aug 2004 09:14:37 +0200 |
User-agent: |
Mutt/1.5.6+20040722i |
The problem is that Octave does not close, so that readlines() cannot
return. Try something like
----
import os, string
[pwrite, pread] = os.popen3("/usr/bin/octave -q")
pwrite.write("x = [1,2,3];\n")
pwrite.write("printf('%f\\n', sum(x));\n")
pwrite.flush()
pwrite.close()
result = pread.readlines()
pread.close()
print ("Sum = %s" % result[0])
----
Regards
Stefan
On Mon, Aug 16, 2004 at 12:43:42PM +1000, Maurice Ling wrote:
> Hi,
>
> I've been trying to find a way to call Octave from Python and a previous
> message in this list uses the following codes...
>
> 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()
>
>
> But python freezes itself after "result = pread.readline()". I'm
> wondering what is wrong?
>
> Thanks
> Cheers
> Maurice
>
> --
> Maurice Han Tong LING, BSc(Hons)(MCB), AdvDipComp, SN
> Doctor of Philosophy (Science) Candidate, The University of Melbourne
> mobile: +61 4 22781753
> +65 96669233
> mailing address: Department of Zoology, The University of Melbourne
> Royal Parade, Parkville, Victoria 3010, Australia
> residential address: 9/41 Dover Street
> Flemington, Victoria 3031, Australia
> email: address@hidden
> resume: http://maurice.vodien.com/maurice_resume.pdf
> www: http://www.geocities.com/beldin79/
>
> The information contained in this message, including its attachment(s),
> is CONFIDENTIAL and solely intended to its addressee(s) only. The
> content of this message, including its attachment(s), may be subjected
> to copyright and privacy laws. If you have received this email in error,
> please let me know by returning this email, and then destroy all copies.
>
> "I cannot discover anyone knows enough to say definitely what is
> and what is not possible" -Henry Ford
> "The difference between the impossible and the possible lies
> in a person's determination" -Tommy Charles Lasorda
>
> begin:vcard
> fn:Maurice Ling
> n:Ling;Maurice
> org:The University of Melbourne;Department of Zoology
> adr:;;Gate 12, Genetics Lane;Parkville;Victoria;3010;Australia
> email;internet:address@hidden
> title:Probatory Ph.D. Candidate
> tel;cell:+61 4 22781753
> x-mozilla-html:FALSE
> url:http://www.geocities.com/beldin79/
> version:2.1
> end:vcard
>
-------------------------------------------------------------
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
-------------------------------------------------------------