Python Forum
'module' object is not subscriptable error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'module' object is not subscriptable error
#1
I am trying to read data from a file called census2010.py containing data in the following format(snippet of the full data):

allData = {'AK': {'Aleutians East': {'pop': 3141, 'tracts': 1},
        'Aleutians West': {'pop': 5561, 'tracts': 2},
        'Anchorage': {'pop': 291826, 'tracts': 55},
        'Bethel': {'pop': 17013, 'tracts': 3},
        'Bristol Bay': {'pop': 997, 'tracts': 1},
        'Denali': {'pop': 1826, 'tracts': 1},
        'Dillingham': {'pop': 4847, 'tracts': 2},
        'Fairbanks North Star': {'pop': 97581, 'tracts': 19},
        'Haines': {'pop': 2508, 'tracts': 1},
        'Hoonah-Angoon': {'pop': 2150, 'tracts': 2},
        'Juneau': {'pop': 31275, 'tracts': 6},etc etc
When I try to do the following in the python shell:
>>>import census2010
>>>census2010['AK']['Anchorage']
I get the following error;

T
Error:
raceback (most recent call last): File "<input>", line 1, in <module> TypeError: 'module' object is not subscriptable
Reply
#2
You want the content of the variable allData, right?

census2010.allData['AK']['Anchorage']
Reply
#3
Not that it is wrong, but is a bit strange to have this as variable in py file. Better make it json file.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
I got it to work now. Not sure what the issue was to be honest.

Thanks for all the replies.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,573 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  I am getting this TypeError: 'TreasureMap' object is not subscriptable. makilakos 2 1,330 May-25-2024, 07:58 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 3,890 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  Need help with 'str' object is not callable error. Fare 4 2,334 Jul-23-2023, 02:25 PM
Last Post: Fare
  working with TLV module Object Jennifer_Jone 3 2,462 Mar-14-2023, 07:54 PM
Last Post: Jennifer_Jone
  Help with python 'not subscriptable' error Extra 3 4,512 Dec-16-2022, 05:55 PM
Last Post: woooee
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 6,871 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  Error in Int object is not subscript-able. kakut 2 1,956 Jul-06-2022, 08:31 AM
Last Post: ibreeden
  TypeError: 'module' object is not callable SyamPothan 4 7,768 Mar-04-2022, 04:44 PM
Last Post: SyamPothan
  'module' object is not callable Racer_x 5 4,661 Nov-04-2021, 03:20 PM
Last Post: Racer_x

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020