Skip to content

Instantly share code, notes, and snippets.

@emileten
Created February 25, 2022 01:24
Show Gist options
  • Save emileten/951a365547433832cf7fe3eb7b0f8046 to your computer and use it in GitHub Desktop.
Save emileten/951a365547433832cf7fe3eb7b0f8046 to your computer and use it in GitHub Desktop.
dict-to-and-from-yaml
from yaml import load, dump, Loader
fp = '/Users/emile/Desktop/testyaml.yaml'
out = {
'a': 1
}
with open(fp, 'w') as f:
dump(out, f)
with open(fp, 'r') as f:
indata = load(f, Loader=Loader)
print(indata)
more = 2
indata['b'] = 2
with open(fp, 'w') as f:
dump(indata, f)
with open(fp, 'r') as f:
indata = load(f, Loader=Loader)
print(indata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment