rich/examples/repr.py

24 lines
589 B
Python
Raw Normal View History

2021-06-18 19:24:05 +00:00
import rich.repr
2021-06-09 17:28:10 +00:00
2021-06-18 19:24:05 +00:00
@rich.repr.auto
2021-06-09 14:39:58 +00:00
class Bird:
def __init__(self, name, eats=None, fly=True, extinct=False):
self.name = name
self.eats = list(eats) if eats else []
self.fly = fly
self.extinct = extinct
2021-06-10 11:26:28 +00:00
2021-06-18 19:44:23 +00:00
# Note that the repr is still generated without Rich
# Try commenting out the following line
2021-06-09 17:28:10 +00:00
from rich import print
2021-06-09 14:39:58 +00:00
BIRDS = {
"gull": Bird("gull", eats=["fish", "chips", "ice cream", "sausage rolls"]),
"penguin": Bird("penguin", eats=["fish"], fly=False),
2021-06-09 17:28:10 +00:00
"dodo": Bird("dodo", eats=["fruit"], fly=False, extinct=True),
2021-06-09 14:39:58 +00:00
}
print(BIRDS)