异常消息:
*之后的参数必须是序列
应该真的说
argument after * must be an iterable。
由于这个原因,通常将星形拆包称为 “可重复拆包” 。 请参阅 PEP
448(其他拆包概述)和PEP
3132(扩展的可迭代拆包)。
编辑:看起来这已 为python 3.5.2和3.6修复。将来会说:
*之后的参数必须是可迭代的
为了解开星标,您的类必须是可迭代的,即它必须定义一个
__iter__返回迭代器的:
class Agent(object): def __init__(self, cards): self.cards = cards def __len__(self): return len(self.cards) def __iter__(self): return (card for card in self.cards)
然后:
In [11]: a = Agent([1, 2, 3, 4])In [12]: print(*a) # Note: in python 2 this will print the tuple1 2 3 4
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)