def export_database(self): data = {} dbsettings = { 'acl': self.context.annotation['acl'], } data['settings.yaml'] = yaml.dump(dbsettings) forms = {} for form in self.context.forms: form_data = {} settings = { "id": form.id, "title": form.title, "fields": form.annotation['fields'], "assigned_rules": form.annotation['assigned_rules'], } form_data["%s.yaml" % form.id] = yaml.dump(settings) form_data["%s.html" % form.id] = form.layout form_data["%s.py" % form.id] = form.code forms[form.id] = form_data data['forms'] = forms return data
def set_last(self, new, feed): with open(self.last_file, "r") as f: lasts = yaml.load(f) lasts[feed] = new with open(self.last_file, "w") as f: yaml.dump(lasts, f, default_flow_style=False)
from pyaml import yaml STUDENT = { 'name': 'Mark', 'age': 22, 'spec': 'math', 'fee': 1000.0, 'isPass': True, 'backlogs': None } yaml_string = yaml.dump(STUDENT) print(yaml_string)
from pyaml import yaml emp_dict = {'name': 'Theja', 'age': 35, 'salary': 1000.0, 'isMarried': True} yaml_string = yaml.dump(emp_dict) print(yaml_string) with open('emp.yaml', 'w') as f: yaml.dump(emp_dict, f) # ed = yaml.load(yaml_string) # /Code/venv/serialization/10Yaml.py:<>: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. # ed = yaml.load(yaml_string) ed = yaml.safe_load(yaml_string) # print('type(ed)', type(ed)) print(ed) for k, v in ed.items(): print(k, ':', v) with open('emp.yaml', 'r') as f: edf = yaml.safe_load(f) print(edf) # age: 35 # isMarried: true # name: Theja # salary: 1000.0 # # type(ed) <class 'dict'>