如何保存带有字典的类对象进行设置

时间:2019-02-13 19:01:16

标签: python dictionary set

我想创建一个类,它的对象应该存储一个字典并将其放入另一个类的对象中,该类存储设置为第一类的对象。

我现在正在以这种格式解析数据库的XML模型(域)

domain name="BinData" type="BLOB" align="L"/ 

,并希望将所有域的集合和域的每个属性设置为对key:value。 我知道仅设置字典就无法做到。但是也许我可以在课堂上解决这个问题? 我尝试过的:

from xml.dom.minidom import parse
class schema:

    def __init__(self,xdb_file):
        self.xdb_file = parse(xdb_file)
        self.domains = self.get_domains()

    def __eq__(self, other):
        if (self.domains == other.domains):
            return True
        else:
            return False

    def get_domains(self):
        domains_set = set()
        domains = self.xdb_file.getElementsByTagName("domain")
        for domain_description in domains:
            domains_set.add(domain(domain_description.attributes.items()))
        return domains_set

class domain:
    def __init__(self,items):
        self.description = dict()
        for item in items:
            self.description[item[0]]=item[1]
        self.description = (self.description)
    def description(self):
        return self.description

    def __eq__(self, other):
        is_Equal = True
        if (set.difference(self.description,other.description)):
            return True
        return False

最后,它显示了有关不可哈希类型域的错误。

0 个答案:

没有答案
相关问题