loading
open in
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def import_db(db_name):
    import json

    def __init__(self, values):
        for key, value in values.items():
            setattr(self, key, value)
        self.fields = values.keys()

    def __str__(self):
        return ', '.join([str(getattr(self, x)) for x in self.fields])

    with open(db_name) as f:
        db = json.load(f)
        for class_name, instances in db.items():
            cls = type(class_name, (), {'__init__': __init__,
                                        '__str__': __str__})
            cls.instances = list()
            for instance in instances:
                cls.instances.append(cls(instance))

            globals()[class_name] = cls

import_db("dn.json")

print(Nerd)
for nerd in Nerd.instances:
    print(nerd)

print(Recruit)
for recruit in Recruit.instances:
    print(recruit)