所以我有一个类 Panini,我必须对其进行初始化,但它一直卡在 assert isinstance(stickers, (int, tuple, set, list)), 'invalid stickers' 行中,当我删除该行时它卡住了在下一个例子中,有人可以告诉我我在这里做错了什么吗?
class Panini:
def __init__(self, stickers):
self.stickers = stickers
#test if stickers is integer or a list/tuple/set of integers
assert isinstance(stickers, (int, tuple, set, list)), 'invalid stickers'
if isinstance(stickers, (set, tuple, list)):
try: int_list = [int(x) for x in stickers]
except ValueError:
raise 'invalid sticker'
#if list or tuple contains duplicate integers(stickers) then these must be included in the collection only once
if isinstance(stickers, (list, tuple)):
my_set = set(stickers)
if isinstance(stickers, tuple): stickers = tuple(my_set)
else: stickers = list(my_set)