Oct2Py only returning the first output argument

做~自己de王妃 提交于 2020-08-04 04:13:27

问题


I'm using Oct2Py in order to use some M-files in my Python code. Let's say that I have this simple Matlab function :

function [a, b] = toto(c);
    a = c;
    b = c + 1;
end

What happens if I call it in Octave is obviously :

>> [x,y] = toto(3)
x = 3
y = 4

Now if I call it in Python, using oct2py :

from oct2py import octave
my_dir = "D:\\My_Dir"
octave.addpath(my_dir)
a,b = octave.toto(3)

This returns :

TypeError: 'int' object is not iterable

It seems like octave.toto(n) only returns the first value, when I'd expect two... Can anyone explain to me what I should be doing ? Thanks


回答1:


In older versions of Oct2Py (3.x and older), the number of output arguments was inferred from the call within Python, so if you wanted multiple outputs, you would simply request both outputs

a, b = octave.toto(3)

However, as of version 4.0 you now need to use the nout kwarg to your function call to explicitly specify the desired number of output arguments

a, b = octave.toto(3, nout=2)

From the 4.0 Release Notes

Removed inferred nout for Octave function calls; it must be explicitly given if not 1. The old behavior was too surprising and relied on internal logic of the CPython interpreter.



来源:https://stackoverflow.com/questions/43394393/oct2py-only-returning-the-first-output-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!