I have two files..
data.py
a1 = {"city":"Boston","code":"BOS"}
a2 = {"city":"Atlanta","code":"ATL"}
a3 = {"city":"Chicago","code":"ORD"}
a4 = ...
a5 = ...
a6 = ...
run.py
from data import *
Class Port_code():
def _init_()
...
def get_code():
x = globals().items()
for i in range(len(x)):
if x[i][1]['city'] == user_input_city:
print x[i][1]['code']
when i run this i get the below Error :
typeerror: 'module' object has no attribute '__getitem__'
is it because i'm using it inside the Class ??
i have a sample code where it gives me what i want it's not inside a class. sample.py
from data import *
user_input=raw_input("enter a City: ")
x = globals().items()
for i in range(len(x)):
if x[i][1]['city'] == user_input:
print x[i][1]['city'],
print " <== "+str(i)+" ==> ",
print x[i][1]['code']
**The Sample.py works Fine ! **
So can i get a clear idea of using inside Class ?