I'm trying to import a CSV file as a dictionary in python but with a set layout.
My code below works
CSV file
key1, value1
Key2, value2
Script
Import cvs
with open('test.csv', mode='r') as infile:
with open('dict.py', mode='w') as outfile:
mydict = {rows[0]:rows[1] for rows in reader}
output.write(mydict)
So my output looks like
{'Key1': 'value1', 'Key2': 'value2'}
How can I make it look like
{
'Key1': 'value1',
'Key2': 'value2',
}
Basically on a newline each?
P.s sorry about formatting done on mobile app