Python Forum
Error in Int object is not subscript-able. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error in Int object is not subscript-able. (/thread-37654.html)



Error in Int object is not subscript-able. - kakut - Jul-06-2022

How to debug this ?

for j in range(len(index)):
        if index[j] < i:
            line_id = humid[index[j]][i] - 1
        else:
            line_id = humid[i][index[j]] - 1
                                              ## index =[2] len(index) =1
                                              ## humid= [[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3], [0, 0, 0, 0]] 
 
-----------------------------------------------------------------------------------
     25     for j in range(len(index)):
     26         if index[j] < i:
---> 27             humid= humid[2][i] - 1
     28         else:
     29             humid= humid[i][index[j]] - 1
 
TypeError: 'int' object is not subscriptable



RE: Error in Int object is not subscript-able. - Larz60+ - Jul-06-2022

Please post errors (complete and unaltered error traceback)
or clearly explain error.


RE: Error in Int object is not subscript-able. - ibreeden - Jul-06-2022

You show 2 parts and the second part seems to be from an error console, but it is not the same as the first part so it is not clear what you mean. But one thing I can say:
(Jul-06-2022, 06:40 AM)kakut Wrote:
---> 27             humid= humid[2][i] - 1
Initially "humid" is a nested list. But after this line is executed, "humid" will be an integer. So if this is executed in a loop, the second time the line is executed it will complain about an integer that is not subscriptable.

You ask how to debug this. The simplest method is to add print statements before the line where the error occurs. There you should print all the variables that are used in the line with the error. Then you can see what goes wrong.