🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

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

User: "Debdatta_Sen"
Altair Employee
Updated by Debdatta_Sen

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

Find more posts tagged with

Sort by:
1 - 6 of 61
    User: "L Moretti"
    New Altair Community Member
    Updated by L Moretti

    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

    User: "robertavarela"
    New Altair Community Member
    Updated by robertavarela

    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

    User: "Debdatta_Sen"
    Altair Employee
    OP
    Updated by Debdatta_Sen

    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?
     

    User: "Debdatta_Sen"
    Altair Employee
    OP
    Updated by Debdatta_Sen

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

    User: "robertavarela"
    New Altair Community Member
    Updated by robertavarela

    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

    User: "Altair Forum User"
    Altair Employee
    Updated by Altair Forum User

    Workaround: 

     

    In Python:

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

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

     

    In  OML:

       getpythonvar('list3')