I was wondering if it's possible to use star unpacking with own classes rather than just builtins like list
and tuple
.
class Agent(object):
def __init__(self, cards):
self.cards = cards
def __len__(self):
return len(self.cards)
def __iter__(self):
return self.cards
And be able to write
agent = Agent([1,2,3,4])
myfunc(*agent)
But I get:
TypeError: visualize() argument after * must be a sequence, not Agent
Which methods do I have to implement in order to make unpacking possible?