Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
He, I am newly to programing with python. I try to initialize two dimensional array with zeros .
The problem is , when I try to add the size to it Python interpreter says: str object can not be interpreted as integer.
This is the line:
if(chain_of_events):
            list_of_lists_of_events = [[0 for x in range(int(self.number))] for y in range(number_of_events)]


Pylance says both arguments in the two range() functions are integers when I hover them with mouse.

What I have tried:

Try to pass magic/hardcoded values to range() functions and with them there is no problem.
Posted
Updated 15-Dec-22 4:08am

1 solution

I fix it.I cast the self.number to integer . Maybe because it is a class member or pylance is lying I had such problem.
 
Share this answer
 
Comments
Richard MacCutchan 15-Dec-22 10:38am    
No, it is more likely because it is a str type.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900