yaml.dump() appending to file rather than overwriting
how do i make set 'hi' to 1 and 'hello' to 1
import yaml
class myClass():
def __init__(self):
self.configFile = open('config.yml', 'r+')
self.config = yaml.load(self.configFile)
self.config['hi'] = 1
self.config['hello'] = 1
yaml.dump(
self.config,
self.configFile,
default_flow_style=False
)
print(self.config)
# returns {'hi': 1, 'hello': 1}
myClass()
config file before:
hi: 0
hello: 0
after:
hi: 0
hello: 0
hi: 1
hello 1
what i want:
hi: 1
hello: 1