How to edit and save TOML content in Python

Viewed 1977
1 Answers

After reading a the file with the toml.load, you can modify your data then overwrite everything with the toml.dump command

import toml
data = toml.load("scenario.toml") 

# Modify field
data['component']['model']='NEWMODELNAME' # Generic item from example you posted

# To use the dump function, you need to open the file in 'write' mode
# It did not work if I just specify file location like in load
f = open("scenario.toml",'w')
toml.dump(data, f)
f.close()
Related