I want to write functions for Octave using Python. Google did not help in finding out whether it was possible to somehow import/include/whatever Python modules in Octave and call them as if they were native .m functions. I looked at Cython, which creates C source code from Python, but it uses Python objects as arguments and return types. Is it possible to use Python modules in Octave?
Unfortunately there is no straightforward way to do this.
Yet, it is always possible to run a Python program and parse the output. In fact
You can execute any shell command using the function system (cmd, flag). The second argument is optional. If it is present, the output of the command is returned by system as a string. If it is not supplied, any output from the command is printed, with the standard output filtered through the pager.
For example:
output = system ("python /home/user/some_algoritmh.py", 1)
There exists a project on Github, pyoctave, which is a C++ extension to Octave and which can call functions of Python modules. You have to compile the extension once to create an oct file and can use this oct file to call Python code.
Code on Github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With