コード例 #1
0
ファイル: importexport.py プロジェクト: mamogmx/rapido.core
    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
コード例 #2
0
 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)
コード例 #3
0
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)
コード例 #4
0
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'>