ws6079 ws6079 - 1 year ago 107
Python Question

Implementing intersection operator for a set-like class in Python

I'm trying to implement a wrapper class which should ideally allow me to get the intersection of its elements using the notation:

a & b

Is there a specific method that I can implement to achieve this? (I know that the individual elements need to implement the

I'm currently getting the following error:

TypeError: unsupported operand type(s) for &: 'PropArray' and 'PropArray'

Answer Source

Try to override:

def __and__(self, *args, **kwargs): # real signature unknown
    """ Return self&value. """

in your class

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download