Oct2Py returns only the first output argument

I am using Oct2Py to use some M files in my Python code. Say 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, 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: object 'int' is not iterable

It seems that octave.toto (n) only returns the first value when I expect two ... Can someone explain to me what I should do? Thanks

+5
source share
1 answer

In earlier versions of Oct2Py (3.x and later), the number of output arguments was pulled out of a call in Python, so if you need multiple outputs, you simply request both outputs

 a, b = octave.toto(3) 

However, starting from version 4.0 you now need to use nout kwarg to call the function to explicitly specify the desired amount of output arguments

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

From Release Notes 4.0

Removed nout for Octave function calls; it should be explicitly specified, if not 1. The old behavior was too unexpected and relied on the internal logic of the CPython interpreter.

+5
source

Source: https://habr.com/ru/post/1266696/


All Articles