用Python打印对象

时间:2017-11-23 18:48:14

标签: python object methods printing

我正在尝试打印一个对象的多个出现,以显示与该对象关联的名称。这就是我现在得到的。如何从每个对象获取信息?下面是我得到的以及我创建此方法的代码。

def get_rarest_card(self):

    card_rarities = Counter(card.rarity for card in self.cardlist if card.rarity !="Basic Land")
    rarity = min(card_rarities, key=lambda card: card_rarities[card])  # Effectively an argmin
    return [card for card in self.cardlist if card.rarity == rarity]

输出结果为:

[<__main__.MagicCard at 0x10b4d65c0>,
 <__main__.MagicCard at 0x10b4d6b38>,
 <__main__.MagicCard at 0x10b4d9c88>,
 <__main__.MagicCard at 0x10b4d2048>,
 <__main__.MagicCard at 0x10b566208>,
 <__main__.MagicCard at 0x10b566668>,
 <__main__.MagicCard at 0x10b4d9780>,
 <__main__.MagicCard at 0x10b4e80b8>,
 <__main__.MagicCard at 0x10b4f4080>,
 <__main__.MagicCard at 0x10b4f4be0>,
 <__main__.MagicCard at 0x10b4f4cc0>,
 <__main__.MagicCard at 0x10b4f47b8>,
 <__main__.MagicCard at 0x10b5002e8>,
 <__main__.MagicCard at 0x10b500e48>,
 <__main__.MagicCard at 0x10b500d30>]

0 个答案:

没有答案