close

[Solved] TypeError: ‘module’ object is not subscriptable

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: ‘module’ object is not subscriptable in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: ‘module’ object is not subscriptable Error Occurs?

Today I get the following error TypeError: ‘module’ object is not subscriptable in python.

How To Solve TypeError: ‘module’ object is not subscriptable Error ?

  1. How To Solve TypeError: 'module' object is not subscriptable Error ?

    To Solve TypeError: 'module' object is not subscriptable Error I got this error because a later from __ import * statement imported a module which bound my variable to something else:

  2. TypeError: 'module' object is not subscriptable

    To Solve TypeError: 'module' object is not subscriptable Error I got this error because a later from __ import * statement imported a module which bound my variable to something else:

Solution 1

import mystuff is importing the module mystuff, not the variable mystuff. To access the variable you’d need to use:

import mystuff
print(mystuff.mystuff['donut'])

EDIT: It’s also possible to import the variable directly, using:

from mystuff import mystuff
print(mystuff['donut'])

Solution 2

I got this error because a later from __ import * statement imported a module which bound my variable to something else:

from stuff_a import d
from stuff_b import *
d['key']

In stuff_b.py, d was bound to a module, hence the error. Lesson learned: avoid importing * from modules.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read