![]() |
'module' object is not subscriptable error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: 'module' object is not subscriptable error (/thread-11366.html) |
'module' object is not subscriptable error - Pengwain - Jul-05-2018 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 etcWhen I try to do the following in the python shell: >>>import census2010 >>>census2010['AK']['Anchorage']I get the following error; T
RE: 'module' object is not subscriptable error - gontajones - Jul-05-2018 You want the content of the variable allData , right?census2010.allData['AK']['Anchorage'] RE: 'module' object is not subscriptable error - buran - Jul-05-2018 Not that it is wrong, but is a bit strange to have this as variable in py file. Better make it json file. RE: 'module' object is not subscriptable error - Pengwain - Jul-08-2018 I got it to work now. Not sure what the issue was to be honest. Thanks for all the replies. |