E1136
Message
Value 'variable_name' is unsubscriptable
Description
Used when there is a reference to an object that initialized as a non-subscriptable object
Explanation
Example:
files = {'txt': None, 'doc': None}
for file in os.listdir():
if file.endswith('.txt'):
files['txt'].append(file)
elif file.endswith('.doc'):
files['doc'].append(file)
print(files['txt'][0])
Pylint will report that "Value 'files['txt'] is unsubscriptable" even though this code will execute without error because files['txt'] was initialized to None, which is unsubscriptable.
Try instead to use:
files = {'txt': [], 'doc': []}
for file in os.listdir():
if file.endswith('.txt'):
files['txt'].append(file)
elif file.endswith('.doc'):
files['doc'].append(file)
print(files['txt'][0])
I am somewhat understanding this solution however I am unable to figure out how to apply it to my code that I am having a problem with. Could you help me out with figuring what the solution is?
The part that I need help with has the comment "problem code starts here".
blog