class test:
def __init__(self):
test_dict = {'1': 'one', '2': 'two'}
def test_function(self):
print self.test_dict
if __name__ == '__main__':
t = test()
print t.test_dict
Error:
AttributeError: test instance has no attribute 'test_dict'
Also, if i execute code: t.test_function()
instead of print t.test_dict
, error occurred too:
AttributeError: test instance has no attribute 'test_dict'
Why? i have defined test_dict in function __init__
, so it should be initialized to each instance, but why does python tell me it cannot find the dict?