def dump_meas_file(data, filename = "", flatten=False):
d = Dumper if filename and not flatten else FlatDumper
d.add_representer(Include, d.include)
if filename:
with open(filename+".tmp", 'w+') as fid:
yaml.dump(data, fid, Dumper=d)
# Upon success
move(filename+".tmp", filename)
with open(filename, 'r') as fid:
contents = fid.read()
return contents
else:
# dump to an IO stream:
# note you need to use the FlatDumper for this to work
out = StringIO()
yaml.dump(data, out, Dumper=d)
ret_string = out.getvalue()
out.close()
return ret_string
评论列表
文章目录