rich
-
提供了丰富的样式化和美化功能
from rich.console import Console from rich.theme import Theme from rich import tracebacktraceback.install()shrek_dict = {"movie_title": "Shrek","release_year": 2001,"characters": {"main_characters": {"Shrek": {"description": "An ogre with a heart of gold.","voice_actor": "Mike Myers","quotes": ["Get out of my swamp!","Ogres are like onions.","Better out than in, I always say."]},"Fiona": {"description": "A princess with a secret.","voice_actor": "Cameron Diaz","quotes": ["I'm not a princess, I'm an ogress!","This is one of those onion things, isn't it?"]},"Donkey": {"description": "A talkative and loyal companion.","voice_actor": "Eddie Murphy","quotes": ["What did I say? I'm just a love machine.","Shrek! What are you doing in my closet?"]}},"supporting_characters": {"Lord_Farquaad": {"description": "A short-tempered and power-hungry lord.","voice_actor": "John Lithgow","quotes": ["People of DuLoc, I am your lord now!","Mirror, mirror, on the wall, is this not the most perfect kingdom of them all?"]},"Dragon": {"description": "A fire-breathing dragon with a soft spot for Donkey.","voice_actor": "Frank Welker","quotes": ["RAWR!","I'm a mother, I have needs!"]}}},"scenes": {"opening": "Shrek wakes up in his swamp and scares away intruders.","fairy_tale_characters": "Shrek meets various fairy tale characters in his swamp.","dragon_tower": "Fiona is trapped in a tower guarded by the Dragon.","final_battle": "Shrek and Donkey rescue Fiona and confront Lord Farquaad."},"themes": ["Acceptance of oneself","True beauty is on the inside","Love conquers all"],"sequels": ["Shrek 2","Shrek the Third","Shrek Forever After"],"trivia": {"fun_facts": ["Shrek was the first animated film to win an Academy Award for Best Animated Feature.","The voice of Shrek was originally going to be provided by Chris Farley, but he passed away before recording was completed."],"box_office": "The film grossed over $484 million worldwide."} }print(shrek_dict) from rich import print # 覆盖原有的print print(shrek_dict)custom_theme = Theme( {"info": "bold cyan","warning": "bold yellow","error": "bold red", })console = Console(theme=custom_theme)def compare_numbers(a,b):console.log(log_locals=True)if a>b:console.print(f'{a} is greater than {b}', style="bold green")elif a<b:console.print(f'{a} is less than {b}', style="bold red")else:console.print(f'{a} is equal to {b}', style="bold yellow")compare_numbers(5,10) compare_numbers(10,5) compare_numbers(5,5)compare_numbers(5,"mzc")