I made a dictionary from one file and need to write it into another file that I will be making edits to. To do this, I made a dictionary from the first file and made it into a string to write it to a second file. Is there a way to convert this string back into a dictionary?
An example of the first file is:
123 2
125 5
128 3
which I make into a dictionary and make into a string in the second file:
def CreateNew(prefix, old_file):
new_file = open('new_file_name', 'w')
new_file.write(str(old_file))
new_file.close()
return new_file
Now, I need to make edits to some of the values in this new file, but am not sure how to make this dictionary string back into a dictionary. I wanted to just print this off to test it out:
def EmpTrans(transactions_file, new_file):
print(dict(new_file))
but this gives me an empty dictionary {}
.
I'm trying not to use any modules for this. I was able to use eval().