Python Bridge - 2D Lists from Python cannot be read back into OML

Debdatta_Sen
Debdatta_Sen
Altair Employee
edited October 2020 in Community Q&A

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

Unable to find an attachment - read this blog

Tagged:

Answers

  • L Moretti
    L Moretti New Altair Community Member
    edited June 2020

    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:

    <?xml version="1.0" encoding="UTF-8"?>Capture.JPG

     

    Regards,

     

    Lorenzo

  • robertavarela
    robertavarela New Altair Community Member
    edited June 2020

    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

  • Debdatta_Sen
    Debdatta_Sen
    Altair Employee
    edited June 2020

    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?
     

  • Debdatta_Sen
    Debdatta_Sen
    Altair Employee
    edited June 2020

    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']

  • robertavarela
    robertavarela New Altair Community Member
    edited June 2020

    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:

    image.png.9dee7c15dddbc0dd883b1c4ba65219b2.png

    Regards,

    Roberta

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2020

    Workaround: 

     

    In Python:

         list2=[(1,1),(2,2),(3,3)]

         list3 = [list(child) for child in list2]

     

    In  OML:

       getpythonvar('list3')