TypeError: object of type 'NoneType' has no len()

Hi there, I am getting constantly the error message that is shown in the screenshot below. Although my App works fine (as intended). Does anyone know how to fix it. Basically what happens is that based on the filtering of a DataTable the remaining values are highlighted in a plot. But it only needs to happen when the remaining number of values is smaller than the total number of values (obviously I do not want to highlight all values in the plot when no filtering happened.

In the code below ‘size’ represents the total number of rows in the unfiltered state. ‘row_ids’ is short for the DataTable property ‘derived_virtual_row_ids’ and based on the documentation supposed to be a list. It returns the ids of the remaining values after filtering. len() should therefore return the number of elements inside the list which is to be understood as the number of remaining rows. Hence the comparison, if its not equal to ‘size’ then the color changes (highlighted) should happen.

What do have to change to get rid of the warning: TypeError: object of type ‘NoneType’ has no len()?

I guess you could do if row_ids is not None and len(row_ids) != size:? I think that if the first condition is false it won’t evaluate the second.

Hi @Lheira, your solutions works. Thank you.

1 Like