[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling Octave from Python
From: |
Maurice Ling |
Subject: |
Re: Calling Octave from Python |
Date: |
Tue, 17 Aug 2004 14:33:40 +1000 |
User-agent: |
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6) Gecko/20040113 |
After changing 2 lines, I've managed to get it running...
1. popen3("/usr/bin/octave -q") to popen2("octave -q","w")
2. result[0] to result
I get the following output, which is wrong
Sum = []
I have no idea what is wrong here. Can anyone help?
At the same time, I'm looking at pexpect (pexpect.sourceforge.net). Does
anyone have any thoughts on how to interoperate python and octave using
pexpect?
Thanks.
Cheers
Maurice
Stefan van der Walt wrote:
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
mauriceling.vcf
Description: Vcard