I have a text file with json data stored in UTF-8 like this:
{'name': u'احسان', 'family': u'شیرزادی'}
I've tried to read and print file data with this code:
file = open("output.txt", "r")
text = file.read()
file.close()
print text
It's OK and exactly as I can see in the file. but when I try to print some part of dictionary by indexes like this:
file = open("output.txt", "r")
text = file.read()
file.close()
print text['name']
An error says that:
print text['name']
TypeError: string indices must be integers, not str
But when I run this code directly I can see It's working:
temp = {'name': u'احسان', 'family': u'شیرزادی'}
print temp['name']
What's the problem here?