Skip to content

Instantly share code, notes, and snippets.

@Merwanski
Created January 21, 2023 20:44
Show Gist options
  • Save Merwanski/045a61c6a76762ee8d87cc2dbbb82bcd to your computer and use it in GitHub Desktop.
Save Merwanski/045a61c6a76762ee8d87cc2dbbb82bcd to your computer and use it in GitHub Desktop.
########################################################################
## MAKE YAML
#!/usr/bin/env python
import yaml
import numpy as np
a = np.matrix('1 2; 3 4')
z = 'hello world'
data = dict(
array = str(a),
string = z
)
with open('data.yml', 'w') as outfile:
yaml.dump(data, outfile, default_flow_style=False)
########################################################################
## READ YAML
#!/usr/bin/env python
import yaml
with open('data.yml') as info:
dict = yaml.load(info)
print(dict)
print(dict.z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment