I have a file containing dictionaries like this:
{'name': 'peter', 'age': '16', 'class': None}
{'name': 'john', 'age': '20', 'class': 'B'}
{'name': 'alex', 'age': '18', 'class': 'C'}
I am trying to read the contents from the file and convert the lines back into dictionaries.
with open(file.txt) as f:
for line in f:
if 'name' in line:
d = json.loads(json.dumps(line.strip()))
print(type(d))
But the type is still str
? How can I get them to be dictionary object again?