Created
February 25, 2022 01:24
-
-
Save emileten/951a365547433832cf7fe3eb7b0f8046 to your computer and use it in GitHub Desktop.
dict-to-and-from-yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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