the python dictionary is fine and printing what i want, printing the dict prints
{'hi': 1, 'hello': 1}
but when i dump it puts the yaml at the end of the file rather than overriding the file
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Latest posts made by Sparky01-
-
RE: yaml.dump() appending to file rather than overwriting
-
yaml.dump() appending to file rather than overwriting
yaml.dump() appending to file rather than overwriting
how do i make set 'hi' to 1 and 'hello' to 1import 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