Hey! I have a txt file with multiple dictionary lines. How could I possible read it literally as a dictionary line or straight as a dictionary line value in to the python file?
my txt file:
{'Cost': 22, 'Income': 1, 'Month': 'a', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
{'Cost': 22, 'Income': 1, 'Month': 'b', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
{'Cost': 22, 'Income': 1, 'Month': 'c', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
I was trying this way, but yet it still reads data as a string..
my txt file:
{'Cost': 22, 'Income': 1, 'Month': 'a', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
{'Cost': 22, 'Income': 1, 'Month': 'b', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
{'Cost': 22, 'Income': 1, 'Month': 'c', 'Cash1': 23, 'Cash2': 2, 'Investments': 3}
I was trying this way, but yet it still reads data as a string..
def Chart_data(self): with open('abc.txt') as f: data = [] for line in (line for line in f if line.rstrip('\n')): data.append(int(eval(line['Cash1'])))Many thanks for your help!