Python script - Debugging problem Empty list

Hello everyone,

I have a small concern about making a Python node.

I am new to programming, but only python can solve my problem.

I created a python script, which compiles on web compilers (eg Pythontutor) but which no longer works on Dynamo …
All he returns to me is “an empty list” …

Is there a specification on compiling the code or an error in the code (maybe pointers)?

Code below:
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

BDD = [['EG_INT','A',15,20,25,32,40,50,65,80,100,125,150,200,250,300],['EG_INT','B',25,25,20,20,20,20,30,30,30,30,30,35,35,35], ['EC_INT','A',15,20,25,32,40,50,65,80,100,125,150,200,250,300],['EC_INT','B',25,25,20,20,20,20,30,30,30,30,30,35,35,35]]
SYST_ELEMENT = ['EG_INT','EC_INT','EG_INT','EC_INT']
DIM_ELEMENT = [150,125,150,100]

#Size of the database
DIM_BDD_L=len(BDD[0])
DIM_BDD_H=len(BDD)

#Size of SYS_ELEMENT
NB_ELE_SYST_ELEMENT=len(SYST_ELEMENT[0])
#Size of DIM_ELEMENT
NB_DIM_ELE=len(DIM_ELEMENT)

#Result list
RESULTAT=[]

for l in range(0,NB_DIM_ELE):    
    for j in range(0,DIM_BDD_H):  
        #Check the string
        if(SYST_ELEMENT[l]==BDD[j][0]):  
            for k in range(2,DIM_BDD_L):  
                #check for the presence of the key in the first indexed list 
                if(BDD[j][k]==DIM_ELEMENT[l]):  
                    RESULTAT.append(BDD[j+1][k]) 
                    break

Capture below :

0_Node

Thank you !

A French guy

It doesn’t seem like you have any inputs or outputs in your python code, unless I am missing something. To output something, at the end of the code should be:
OUT = outputVariable

And input should be at the top of your code as:
var1 = IN[0]
var2 = IN[1]
… and so on.

Assuming you want RESULTAT as the output of the code, it should be:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

BDD = IN[0]
SYST_ELEMENT = IN[1]
DIM_ELEMENT = IN[2]

#Size of the database
DIM_BDD_L=len(BDD[0])
DIM_BDD_H=len(BDD)

#Size of SYS_ELEMENT
NB_ELE_SYST_ELEMENT=len(SYST_ELEMENT[0])
#Size of DIM_ELEMENT
NB_DIM_ELE=len(DIM_ELEMENT)

#Result list
RESULTAT=[]

for l in range(0,NB_DIM_ELE):    
    for j in range(0,DIM_BDD_H):  
        #Check the string
        if(SYST_ELEMENT[l]==BDD[j][0]):  
            for k in range(2,DIM_BDD_L):  
                #check for the presence of the key in the first indexed list 
                if(BDD[j][k]==DIM_ELEMENT[l]):  
                    RESULTAT.append(BDD[j+1][k]) 
                    break
                    
OUT = RESULTAT

Yep sorry, I put the test code for pythontutor.

I test your code and is the same return…
1_Node

I already had this problem or the OUT does not return anything even though the list is complete.
It’s a mystery for me !

HI @Blond
try Flatten the list in IN[0] , use Flatten Node

I plugged in your code, it worked for me and got a list of 4 elements, each with a value of 30. I also tried out the code by hand and I am not sure what you are trying to get at because it always leads back to the same element inside of BDD. Could you explain what you are trying to achieve with the code?

Hello @khuzaimah.ElecEng

Same Result. An empty list

you are right, according to your code it’s not right to Flatten the input,
if you please explain what are you want to do

I @kennyb6

The code that you send in your previous post (with input) is the right one.

the code set early post is the one set in the web compiler (pythontutor - http://www.pythontutor.com/)

Ok ! @kennyb6 @khuzaimah.ElecEng
Concerning the functioning of the code, the principle is as follows:
We interrogate the first list of a database/BDD to match to take the information of the second.
The list of BDD is paired with the key of the first matched element (e.g EC_INT, EG_INT) where we take the information.

In the last Test, with the entries of my program and with input seizure … and I fall back on the empty list. It is the same Python script

Capture below

Thank you for your interest

It doesn’t seem like there is anything wrong with the code and since there aren’t any errors in compiling, I would guess that the problem is in the inputs. Maybe none of the inputs satisfy the if statements so returning an empty list is because the list is actually empty.

Since you know the inputs from the Test code work, try using those as dynamo blocks and insert them into the main python script.

EDIT: As in connect them into IN[0]…[2]

1 Like

Have you thought about your inputs, are they numbers/string where they should be this is because you may be trying to match a string to a number and of course they wont match. Therefore you are getting a empty list as your output.

1 Like

Okay
I’ll do tests in this direction!

Also, by chance, will there be a node to test the format of a value?

Problem Solve

You’right

The origin of the problem came from the fact that the BDD was in string (import from Excel spreadsheet with the bad boolean).

Thanks

If my memory is right they generally read excel as strings so you have to convert numbers from a string to a number where required.

There is a node called Object.Type and this will give you a output as follows depending on what is inputted.

System.Double = A double-precision floating-point number to be rounded.
System.Int32 = The number of fractional digits in the return value.
System.String = Text