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])

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License