python create a set of class 1

python create a set of class

class GlobeLearningTable(object):
    def __init__(self,mac,port,dpid):
        self.mac = mac
        self.port = port
        self.dpid = dpid

    def __hash__(self):
        return hash((self.mac, self.port, self.dpid))

    def __eq__(self, other):
        if not isinstance(other, type(self)): return NotImplemented
        return self.mac == other.mac and self.port == other.port and self.dpid == other.dpid

Here is what the above code is Doing:
1. The class is defined as a subclass of object.
2. The __init__ method is called when the class is instantiated.
3. The __hash__ method is called when the object is hashed.
4. The __eq__ method is called when the object is compared for equality.

Similar Posts