Q:

Concise way for wildcard match among objects?

I have a Match class which needs to implement a wildcard match method. This method will check all the attributes of the class with another object of the same class. If both are same or either is a * then it is a match. This logic is true for all the attributes in a class.
Please refer to the implementation of the wildcard_match method below.
The problem is if I add more attributes to the class, or if the number of attributes is large, I need to manually keep on adding to the method. So I need a concise, DRY way of implementing the method.
Any help is appreciated.
class Match:
    def __init__(self):
        self.src = "h%s" % random.randint(1, SRC)
        self.dst = "h%s" % random.randint(1, DST)
        self.proto = random.choice(L4_PROTO)
        self.src_port = str(random.randint(2000, 5000))
        self.dst_port =  random.choice(L4_PORTS)

    def __members(self):
        return (self.src, self.dst, self.proto, self.src_port, self.dst_port)

    def __hash__(self):
        return hash(self.__members())

    def __eq__(self, other):
        """ Exact match check """
        if isinstance(other, self.__class__):
            return self.__members() == other.__members()
        else:
            return False

    def wildcard_match(self, other):
        """ Check whether the two matches are a wildcard match """
        if isinstance(other, self.__class__):
            if self.src != "*" and other.src != "*" and self.src != other.src:
                return False
            if self.dst != "*" and other.dst != "*" and self.dst != other.dst:
                return False
            if self.proto != "*" and other.proto != "*" and self.proto != other.proto:
                return False
            if self.src_port != "*" and other.src_port != "*" and self.src_port != other.src_port:
                return False
            if self.dst_port != "*" and other.dst_port != "*" and self.dst_port != other.dst_port:
                return False
            return True
        else:
            return False

A:

You can use your classes __dict__ which contains all attributes you defined:
def wildcard_match(self, other):
    """ Check whether the two matches are a wildcard match """
    if isinstance(other, self.__class__):
        for attr_name in self.__dict__:
            self_attr = self.__getattr__(attr_name)
            other_attr = other.__getattr__(attr_name)
            if self_attr != "*" and other_attr != "*" and self_attr != other_attr:
                return False
        return True
    else:
        return False

