Python Forum

Full Version: 'module' object is not subscriptable error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
You want the content of the variable allData, right?

census2010.allData['AK']['Anchorage']
Not that it is wrong, but is a bit strange to have this as variable in py file. Better make it json file.
I got it to work now. Not sure what the issue was to be honest.

Thanks for all the replies.