def fetch(self, criterion=None):
"""Fetch one or several cards from the collection.
* Given (None, 0, 1): fetch first card from the collection
* Given a specific card: fetch that specific card
* Given a number > 1: return a list of cards
:rtype: Card or list of Card
"""
if not self.cards:
raise exceptions.NoCardsLeft()
try:
if not criterion or criterion == 1:
return self.cards.pop(0)
if isinstance(criterion, Integral):
return [self.cards.pop(i) for i in range(criterion)]
return self.cards.pop(self.cards.index(criterion))
except (IndexError, ValueError):
raise exceptions.CardNotFound()
评论列表
文章目录