Python Bridge - 2D Lists from Python cannot be read back into OML
In the attached script, one can see that 1D lists such as list1=[1,2,3] can be imported in OML without a hassle.
Whereas when I try to import a list2=[(1,1),(2,2),(3,3)], I receive an error message in OML saying that list2 does not exist.
I use the command getpythonvar().
Am I missing something?
I have attached a file that can be used to reproduce my error message.
I am using Compose 2019.3
Thanks a bunch,
Deb
Answers
-
-
What you can do is to convert your tuple into list. An example:
t = ('my', 'name', 'is', 'mr', 'tuple')
l = list(t)
And then use getpythonvar to retrieve the variable.
Regards,
Roberta
0 -
Altair Forum User said:
Hello Debdatta Sen,
I think the issue is in what is contained in the list: tuples.
Tuples are not supported. You can look at the supported Python DataTypes in the help page.
Here a screenshot:
Regards,
Lorenzo
Thanks for the quick response!!
Are there any plans to support them in the future?
0 -
Altair Forum User said:
What you can do is to convert your tuple into list. An example:
t = ('my', 'name', 'is', 'mr', 'tuple')
l = list(t)
And then use getpythonvar to retrieve the variable.
Regards,
Roberta
Thanks, for the tip!
But I think it works for 1D lists again isn't it?
I have a tuple again as soon as I have a single 2D element as in t = [('my', 'name'), 'is', 'mr', 'tuple']0 -
In this case, you'd need to use list function again in those tuples inside the list:
l[0] = list(l[0])
Which would generate this variable:
[['my', 'name'], 'is', 'mr', 'tuple']With getpythonvar, the output would be a cell within a cell:
Regards,
Roberta
0 -
Workaround:
In Python:
list2=[(1,1),(2,2),(3,3)]
list3 = [list(child) for child in list2]
In OML:
getpythonvar('list3')
0