I have some code that creates a dictionary and pastes it into a text file. But it pastes the dictionary as one line. Below I have the code and the textfile it creates.
print('Writing to Optimal_System.txt in %s\n' %(os.getcwd()))
f = open('Optimal_System.txt','w')
f.write(str(optimal_system))
f.close
Is there any way to make the textfile give each key-value pair it's own line like this?
{'Optimal Temperature (K)': 425
'Optimal Pressure (kPa)': 100
...
}

Using formatting string and assuming that
optimal_systemis your dictionary:EDIT
As pointed by @wwii, the code above can be also written as:
And the string can be formatted using formatted string literals, available since python 3.6, hence
f'{k}: {v}\n'instead of"{}: {}\n".format(k, v).