[{"data":1,"prerenderedAt":1642},["ShallowReactive",2],{"post-2026-02-11-python-rich":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":15,"_type":1636,"_id":1637,"_source":1638,"_file":1639,"_stem":1640,"_extension":1641},"\u002Fblog\u002F2026-02-11-python-rich","blog",false,"","Rich 终端美化示例","Python Rich库使用教程，终端美化、Panel面板、Console API、日志输出与JSON格式化。","2026-02-11",[12,13,14],"Python","终端","美化",{"type":16,"children":17,"toc":1632},"root",[18,26,36,76,85,109,176,183,191,455,462,484,553,586,591,655,662,668,684,707,715,729,737,784,811,880,894,908,916,1027,1035,1058,1066,1097,1102,1165,1172,1299,1303,1418,1425,1441,1455,1460,1483,1493,1507,1512,1546,1550,1627],{"type":19,"tag":20,"props":21,"children":23},"element","h3",{"id":22},"简单入门",[24],{"type":25,"value":22},"text",{"type":19,"tag":27,"props":28,"children":29},"ol",{},[30],{"type":19,"tag":31,"props":32,"children":33},"li",{},[34],{"type":25,"value":35},"可以在 REPL 中安装 Rich，这样 Python 数据结构会自动漂亮地打印并标注语法。具体做法如下：",{"type":19,"tag":37,"props":38,"children":42},"pre",{"className":39,"code":40,"language":41,"meta":7,"style":7},"language-python shiki shiki-themes github-dark","from rich import print as rprint  \nprint({\"原生print\":True})  \nrprint({\"现在print\":True})\n","python",[43],{"type":19,"tag":44,"props":45,"children":46},"code",{"__ignoreMap":7},[47,58,67],{"type":19,"tag":48,"props":49,"children":52},"span",{"class":50,"line":51},"line",1,[53],{"type":19,"tag":48,"props":54,"children":55},{},[56],{"type":25,"value":57},"from rich import print as rprint  \n",{"type":19,"tag":48,"props":59,"children":61},{"class":50,"line":60},2,[62],{"type":19,"tag":48,"props":63,"children":64},{},[65],{"type":25,"value":66},"print({\"原生print\":True})  \n",{"type":19,"tag":48,"props":68,"children":70},{"class":50,"line":69},3,[71],{"type":19,"tag":48,"props":72,"children":73},{},[74],{"type":25,"value":75},"rprint({\"现在print\":True})\n",{"type":19,"tag":77,"props":78,"children":79},"p",{},[80],{"type":19,"tag":81,"props":82,"children":84},"img",{"alt":7,"src":83},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211114405172.png",[],{"type":19,"tag":27,"props":86,"children":87},{"start":60},[88],{"type":19,"tag":31,"props":89,"children":90},{},[91,93,99,101,107],{"type":25,"value":92},"利用 ",{"type":19,"tag":44,"props":94,"children":96},{"className":95},[],[97],{"type":25,"value":98},"rich",{"type":25,"value":100}," 库的 ",{"type":19,"tag":44,"props":102,"children":104},{"className":103},[],[105],{"type":25,"value":106},"Panel",{"type":25,"value":108}," 组件创建一个带边框的面板，并输出醒目的文本，代码如下：",{"type":19,"tag":37,"props":110,"children":112},{"className":39,"code":111,"language":41,"meta":7,"style":7},"# 导入rich库的Panel组件和增强版print函数  \nfrom rich.panel import Panel  \nfrom rich import print  \n  \n# 创建并打印带样式的面板  \n# Panel.fit() 会自适应内容宽度，border_style设置边框样式，文本使用加粗黄色  \nprint(Panel.fit(\"[bold yellow]Hi, I'm a Panel[\u002Fbold yellow]\", border_style=\"red\"))\n",[113],{"type":19,"tag":44,"props":114,"children":115},{"__ignoreMap":7},[116,124,132,140,149,158,167],{"type":19,"tag":48,"props":117,"children":118},{"class":50,"line":51},[119],{"type":19,"tag":48,"props":120,"children":121},{},[122],{"type":25,"value":123},"# 导入rich库的Panel组件和增强版print函数  \n",{"type":19,"tag":48,"props":125,"children":126},{"class":50,"line":60},[127],{"type":19,"tag":48,"props":128,"children":129},{},[130],{"type":25,"value":131},"from rich.panel import Panel  \n",{"type":19,"tag":48,"props":133,"children":134},{"class":50,"line":69},[135],{"type":19,"tag":48,"props":136,"children":137},{},[138],{"type":25,"value":139},"from rich import print  \n",{"type":19,"tag":48,"props":141,"children":143},{"class":50,"line":142},4,[144],{"type":19,"tag":48,"props":145,"children":146},{},[147],{"type":25,"value":148},"  \n",{"type":19,"tag":48,"props":150,"children":152},{"class":50,"line":151},5,[153],{"type":19,"tag":48,"props":154,"children":155},{},[156],{"type":25,"value":157},"# 创建并打印带样式的面板  \n",{"type":19,"tag":48,"props":159,"children":161},{"class":50,"line":160},6,[162],{"type":19,"tag":48,"props":163,"children":164},{},[165],{"type":25,"value":166},"# Panel.fit() 会自适应内容宽度，border_style设置边框样式，文本使用加粗黄色  \n",{"type":19,"tag":48,"props":168,"children":170},{"class":50,"line":169},7,[171],{"type":19,"tag":48,"props":172,"children":173},{},[174],{"type":25,"value":175},"print(Panel.fit(\"[bold yellow]Hi, I'm a Panel[\u002Fbold yellow]\", border_style=\"red\"))\n",{"type":19,"tag":77,"props":177,"children":178},{},[179],{"type":19,"tag":81,"props":180,"children":182},{"alt":7,"src":181},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211113634572.png",[],{"type":19,"tag":27,"props":184,"children":185},{"start":69},[186],{"type":19,"tag":31,"props":187,"children":188},{},[189],{"type":25,"value":190},"设置边框和文字颜色及样式效果：",{"type":19,"tag":37,"props":192,"children":194},{"className":39,"code":193,"language":41,"meta":7,"style":7},"from rich.panel import Panel  \nfrom rich import print  \nfrom rich import box  \nfrom rich.text import Text  \n  \n# 1. 基础边框样式（已验证能正常运行）  \nprint(Panel(\"圆角边框\", border_style=\"green\", expand=False, box=box.ROUNDED))  \nprint(Panel(\"粗边框\", border_style=\"blue\", expand=False, box=box.HEAVY))  \nprint(Panel(\"ASCII边框\", border_style=\"yellow\", expand=False, box=box.ASCII))  \n  \n# 文本+底色（仅文本）  \ntext = Text(\"渐变文本\", style=\"bold red on yellow\")  \npanel = Panel(text, border_style=\"bright_cyan\",expand=False)  \nprint(panel)  \n  \n# 模拟文字渐变：每个字符不同颜色  \ntext = Text()  \ncolors = [\"red\", \"yellow\", \"green\", \"cyan\", \"blue\"]  \nfor i, color in enumerate(colors):  \n    text.append(f\"渐{i}\", style=color)  \nprint(Panel(text, border_style=\"white\", expand=False))  \n  \n# 模拟边框渐变（多个Panel拼接）  \nfrom rich.columns import Columns  \npanels = [  \n    Panel(\"左\", border_style=\"red\"),  \n    Panel(\"中\", border_style=\"yellow\"),  \n    Panel(\"右\", border_style=\"green\")  \n]  \nprint(Columns(panels))\n",[195],{"type":19,"tag":44,"props":196,"children":197},{"__ignoreMap":7},[198,205,212,220,228,235,243,251,260,269,277,286,295,304,313,321,330,339,348,357,366,375,383,392,401,410,419,428,437,446],{"type":19,"tag":48,"props":199,"children":200},{"class":50,"line":51},[201],{"type":19,"tag":48,"props":202,"children":203},{},[204],{"type":25,"value":131},{"type":19,"tag":48,"props":206,"children":207},{"class":50,"line":60},[208],{"type":19,"tag":48,"props":209,"children":210},{},[211],{"type":25,"value":139},{"type":19,"tag":48,"props":213,"children":214},{"class":50,"line":69},[215],{"type":19,"tag":48,"props":216,"children":217},{},[218],{"type":25,"value":219},"from rich import box  \n",{"type":19,"tag":48,"props":221,"children":222},{"class":50,"line":142},[223],{"type":19,"tag":48,"props":224,"children":225},{},[226],{"type":25,"value":227},"from rich.text import Text  \n",{"type":19,"tag":48,"props":229,"children":230},{"class":50,"line":151},[231],{"type":19,"tag":48,"props":232,"children":233},{},[234],{"type":25,"value":148},{"type":19,"tag":48,"props":236,"children":237},{"class":50,"line":160},[238],{"type":19,"tag":48,"props":239,"children":240},{},[241],{"type":25,"value":242},"# 1. 基础边框样式（已验证能正常运行）  \n",{"type":19,"tag":48,"props":244,"children":245},{"class":50,"line":169},[246],{"type":19,"tag":48,"props":247,"children":248},{},[249],{"type":25,"value":250},"print(Panel(\"圆角边框\", border_style=\"green\", expand=False, box=box.ROUNDED))  \n",{"type":19,"tag":48,"props":252,"children":254},{"class":50,"line":253},8,[255],{"type":19,"tag":48,"props":256,"children":257},{},[258],{"type":25,"value":259},"print(Panel(\"粗边框\", border_style=\"blue\", expand=False, box=box.HEAVY))  \n",{"type":19,"tag":48,"props":261,"children":263},{"class":50,"line":262},9,[264],{"type":19,"tag":48,"props":265,"children":266},{},[267],{"type":25,"value":268},"print(Panel(\"ASCII边框\", border_style=\"yellow\", expand=False, box=box.ASCII))  \n",{"type":19,"tag":48,"props":270,"children":272},{"class":50,"line":271},10,[273],{"type":19,"tag":48,"props":274,"children":275},{},[276],{"type":25,"value":148},{"type":19,"tag":48,"props":278,"children":280},{"class":50,"line":279},11,[281],{"type":19,"tag":48,"props":282,"children":283},{},[284],{"type":25,"value":285},"# 文本+底色（仅文本）  \n",{"type":19,"tag":48,"props":287,"children":289},{"class":50,"line":288},12,[290],{"type":19,"tag":48,"props":291,"children":292},{},[293],{"type":25,"value":294},"text = Text(\"渐变文本\", style=\"bold red on yellow\")  \n",{"type":19,"tag":48,"props":296,"children":298},{"class":50,"line":297},13,[299],{"type":19,"tag":48,"props":300,"children":301},{},[302],{"type":25,"value":303},"panel = Panel(text, border_style=\"bright_cyan\",expand=False)  \n",{"type":19,"tag":48,"props":305,"children":307},{"class":50,"line":306},14,[308],{"type":19,"tag":48,"props":309,"children":310},{},[311],{"type":25,"value":312},"print(panel)  \n",{"type":19,"tag":48,"props":314,"children":316},{"class":50,"line":315},15,[317],{"type":19,"tag":48,"props":318,"children":319},{},[320],{"type":25,"value":148},{"type":19,"tag":48,"props":322,"children":324},{"class":50,"line":323},16,[325],{"type":19,"tag":48,"props":326,"children":327},{},[328],{"type":25,"value":329},"# 模拟文字渐变：每个字符不同颜色  \n",{"type":19,"tag":48,"props":331,"children":333},{"class":50,"line":332},17,[334],{"type":19,"tag":48,"props":335,"children":336},{},[337],{"type":25,"value":338},"text = Text()  \n",{"type":19,"tag":48,"props":340,"children":342},{"class":50,"line":341},18,[343],{"type":19,"tag":48,"props":344,"children":345},{},[346],{"type":25,"value":347},"colors = [\"red\", \"yellow\", \"green\", \"cyan\", \"blue\"]  \n",{"type":19,"tag":48,"props":349,"children":351},{"class":50,"line":350},19,[352],{"type":19,"tag":48,"props":353,"children":354},{},[355],{"type":25,"value":356},"for i, color in enumerate(colors):  \n",{"type":19,"tag":48,"props":358,"children":360},{"class":50,"line":359},20,[361],{"type":19,"tag":48,"props":362,"children":363},{},[364],{"type":25,"value":365},"    text.append(f\"渐{i}\", style=color)  \n",{"type":19,"tag":48,"props":367,"children":369},{"class":50,"line":368},21,[370],{"type":19,"tag":48,"props":371,"children":372},{},[373],{"type":25,"value":374},"print(Panel(text, border_style=\"white\", expand=False))  \n",{"type":19,"tag":48,"props":376,"children":378},{"class":50,"line":377},22,[379],{"type":19,"tag":48,"props":380,"children":381},{},[382],{"type":25,"value":148},{"type":19,"tag":48,"props":384,"children":386},{"class":50,"line":385},23,[387],{"type":19,"tag":48,"props":388,"children":389},{},[390],{"type":25,"value":391},"# 模拟边框渐变（多个Panel拼接）  \n",{"type":19,"tag":48,"props":393,"children":395},{"class":50,"line":394},24,[396],{"type":19,"tag":48,"props":397,"children":398},{},[399],{"type":25,"value":400},"from rich.columns import Columns  \n",{"type":19,"tag":48,"props":402,"children":404},{"class":50,"line":403},25,[405],{"type":19,"tag":48,"props":406,"children":407},{},[408],{"type":25,"value":409},"panels = [  \n",{"type":19,"tag":48,"props":411,"children":413},{"class":50,"line":412},26,[414],{"type":19,"tag":48,"props":415,"children":416},{},[417],{"type":25,"value":418},"    Panel(\"左\", border_style=\"red\"),  \n",{"type":19,"tag":48,"props":420,"children":422},{"class":50,"line":421},27,[423],{"type":19,"tag":48,"props":424,"children":425},{},[426],{"type":25,"value":427},"    Panel(\"中\", border_style=\"yellow\"),  \n",{"type":19,"tag":48,"props":429,"children":431},{"class":50,"line":430},28,[432],{"type":19,"tag":48,"props":433,"children":434},{},[435],{"type":25,"value":436},"    Panel(\"右\", border_style=\"green\")  \n",{"type":19,"tag":48,"props":438,"children":440},{"class":50,"line":439},29,[441],{"type":19,"tag":48,"props":442,"children":443},{},[444],{"type":25,"value":445},"]  \n",{"type":19,"tag":48,"props":447,"children":449},{"class":50,"line":448},30,[450],{"type":19,"tag":48,"props":451,"children":452},{},[453],{"type":25,"value":454},"print(Columns(panels))\n",{"type":19,"tag":77,"props":456,"children":457},{},[458],{"type":19,"tag":81,"props":459,"children":461},{"alt":7,"src":460},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211113534769.png",[],{"type":19,"tag":27,"props":463,"children":464},{"start":142},[465],{"type":19,"tag":31,"props":466,"children":467},{},[468,474,476,482],{"type":19,"tag":44,"props":469,"children":471},{"className":470},[],[472],{"type":25,"value":473},"inspect()",{"type":25,"value":475}," 功能：",{"type":19,"tag":477,"props":478,"children":479},"strong",{},[480],{"type":25,"value":481},"详细查看对象的属性和方法",{"type":25,"value":483},"。你的代码效果：",{"type":19,"tag":37,"props":485,"children":487},{"className":39,"code":486,"language":41,"meta":7,"style":7},"from rich import inspect  \n  \n# 先创建一个对象，此处以Color对象为例  \nfrom rich.color import Color  \ncolor = Color.parse(\"red\")  \n  \n# inspect(对象名[, methods=True\u002FFalse])  \ninspect(color, methods=True)\n",[488],{"type":19,"tag":44,"props":489,"children":490},{"__ignoreMap":7},[491,499,506,514,522,530,537,545],{"type":19,"tag":48,"props":492,"children":493},{"class":50,"line":51},[494],{"type":19,"tag":48,"props":495,"children":496},{},[497],{"type":25,"value":498},"from rich import inspect  \n",{"type":19,"tag":48,"props":500,"children":501},{"class":50,"line":60},[502],{"type":19,"tag":48,"props":503,"children":504},{},[505],{"type":25,"value":148},{"type":19,"tag":48,"props":507,"children":508},{"class":50,"line":69},[509],{"type":19,"tag":48,"props":510,"children":511},{},[512],{"type":25,"value":513},"# 先创建一个对象，此处以Color对象为例  \n",{"type":19,"tag":48,"props":515,"children":516},{"class":50,"line":142},[517],{"type":19,"tag":48,"props":518,"children":519},{},[520],{"type":25,"value":521},"from rich.color import Color  \n",{"type":19,"tag":48,"props":523,"children":524},{"class":50,"line":151},[525],{"type":19,"tag":48,"props":526,"children":527},{},[528],{"type":25,"value":529},"color = Color.parse(\"red\")  \n",{"type":19,"tag":48,"props":531,"children":532},{"class":50,"line":160},[533],{"type":19,"tag":48,"props":534,"children":535},{},[536],{"type":25,"value":148},{"type":19,"tag":48,"props":538,"children":539},{"class":50,"line":169},[540],{"type":19,"tag":48,"props":541,"children":542},{},[543],{"type":25,"value":544},"# inspect(对象名[, methods=True\u002FFalse])  \n",{"type":19,"tag":48,"props":546,"children":547},{"class":50,"line":253},[548],{"type":19,"tag":48,"props":549,"children":550},{},[551],{"type":25,"value":552},"inspect(color, methods=True)\n",{"type":19,"tag":554,"props":555,"children":556},"ul",{},[557,568],{"type":19,"tag":31,"props":558,"children":559},{},[560,566],{"type":19,"tag":44,"props":561,"children":563},{"className":562},[],[564],{"type":25,"value":565},"inspect(color, methods=True)",{"type":25,"value":567},"：显示 Color 对象所有属性和方法",{"type":19,"tag":31,"props":569,"children":570},{},[571,577,579,584],{"type":19,"tag":44,"props":572,"children":574},{"className":573},[],[575],{"type":25,"value":576},"methods=True",{"type":25,"value":578}," 表示",{"type":19,"tag":477,"props":580,"children":581},{},[582],{"type":25,"value":583},"同时显示方法",{"type":25,"value":585},"（默认只显示属性）",{"type":19,"tag":77,"props":587,"children":588},{},[589],{"type":25,"value":590},"输出会包含以下内容，清晰列出对象内部结构：",{"type":19,"tag":37,"props":592,"children":595},{"className":593,"code":594,"language":25,"meta":7,"style":7},"language-text shiki shiki-themes github-dark","╭─────────────────────────────────────────────────────────────╮\n│ \u003Crich.color.Color>                                          │\n╰─────────────────────────────────────────────────────────────╯\n┌─────────────┬───────────────────────────────────────────────┐\n│ attributes  │ color, ...                                    │\n│ methods     │ __init__, parse, ...                          │\n└─────────────┴───────────────────────────────────────────────┘\n",[596],{"type":19,"tag":44,"props":597,"children":598},{"__ignoreMap":7},[599,607,615,623,631,639,647],{"type":19,"tag":48,"props":600,"children":601},{"class":50,"line":51},[602],{"type":19,"tag":48,"props":603,"children":604},{},[605],{"type":25,"value":606},"╭─────────────────────────────────────────────────────────────╮\n",{"type":19,"tag":48,"props":608,"children":609},{"class":50,"line":60},[610],{"type":19,"tag":48,"props":611,"children":612},{},[613],{"type":25,"value":614},"│ \u003Crich.color.Color>                                          │\n",{"type":19,"tag":48,"props":616,"children":617},{"class":50,"line":69},[618],{"type":19,"tag":48,"props":619,"children":620},{},[621],{"type":25,"value":622},"╰─────────────────────────────────────────────────────────────╯\n",{"type":19,"tag":48,"props":624,"children":625},{"class":50,"line":142},[626],{"type":19,"tag":48,"props":627,"children":628},{},[629],{"type":25,"value":630},"┌─────────────┬───────────────────────────────────────────────┐\n",{"type":19,"tag":48,"props":632,"children":633},{"class":50,"line":151},[634],{"type":19,"tag":48,"props":635,"children":636},{},[637],{"type":25,"value":638},"│ attributes  │ color, ...                                    │\n",{"type":19,"tag":48,"props":640,"children":641},{"class":50,"line":160},[642],{"type":19,"tag":48,"props":643,"children":644},{},[645],{"type":25,"value":646},"│ methods     │ __init__, parse, ...                          │\n",{"type":19,"tag":48,"props":648,"children":649},{"class":50,"line":169},[650],{"type":19,"tag":48,"props":651,"children":652},{},[653],{"type":25,"value":654},"└─────────────┴───────────────────────────────────────────────┘\n",{"type":19,"tag":77,"props":656,"children":657},{},[658],{"type":19,"tag":81,"props":659,"children":661},{"alt":7,"src":660},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211132234945.png",[],{"type":19,"tag":20,"props":663,"children":665},{"id":664},"console-api",[666],{"type":25,"value":667},"Console API",{"type":19,"tag":27,"props":669,"children":670},{},[671],{"type":19,"tag":31,"props":672,"children":673},{},[674,676,682],{"type":25,"value":675},"在项目添加一个名为 ",{"type":19,"tag":44,"props":677,"children":679},{"className":678},[],[680],{"type":25,"value":681},"console.py",{"type":25,"value":683}," 的文件：",{"type":19,"tag":37,"props":685,"children":687},{"className":39,"code":686,"language":41,"meta":7,"style":7},"from rich.console import Console\nconsole = Console()\n",[688],{"type":19,"tag":44,"props":689,"children":690},{"__ignoreMap":7},[691,699],{"type":19,"tag":48,"props":692,"children":693},{"class":50,"line":51},[694],{"type":19,"tag":48,"props":695,"children":696},{},[697],{"type":25,"value":698},"from rich.console import Console\n",{"type":19,"tag":48,"props":700,"children":701},{"class":50,"line":60},[702],{"type":19,"tag":48,"props":703,"children":704},{},[705],{"type":25,"value":706},"console = Console()\n",{"type":19,"tag":27,"props":708,"children":709},{"start":60},[710],{"type":19,"tag":31,"props":711,"children":712},{},[713],{"type":25,"value":714},"然后可以在项目的任何位置导入控制台：",{"type":19,"tag":37,"props":716,"children":718},{"className":39,"code":717,"language":41,"meta":7,"style":7},"from 项目名.console import console\n",[719],{"type":19,"tag":44,"props":720,"children":721},{"__ignoreMap":7},[722],{"type":19,"tag":48,"props":723,"children":724},{"class":50,"line":51},[725],{"type":19,"tag":48,"props":726,"children":727},{},[728],{"type":25,"value":717},{"type":19,"tag":27,"props":730,"children":731},{"start":69},[732],{"type":19,"tag":31,"props":733,"children":734},{},[735],{"type":25,"value":736},"控制台会在渲染时自动检测到一些属性。",{"type":19,"tag":554,"props":738,"children":739},{},[740,751,762,773],{"type":19,"tag":31,"props":741,"children":742},{},[743,749],{"type":19,"tag":44,"props":744,"children":746},{"className":745},[],[747],{"type":25,"value":748},"size",{"type":25,"value":750}," 是终端当前的尺寸（如果你调整窗口大小，尺寸可能会改变）。",{"type":19,"tag":31,"props":752,"children":753},{},[754,760],{"type":19,"tag":44,"props":755,"children":757},{"className":756},[],[758],{"type":25,"value":759},"encoding",{"type":25,"value":761}," 是默认编码（通常为“UTF-8”）。",{"type":19,"tag":31,"props":763,"children":764},{},[765,771],{"type":19,"tag":44,"props":766,"children":768},{"className":767},[],[769],{"type":25,"value":770},"is_terminal",{"type":25,"value":772}," 是一个布尔值，用于指示控制台实例是否正在写入终端。",{"type":19,"tag":31,"props":774,"children":775},{},[776,782],{"type":19,"tag":44,"props":777,"children":779},{"className":778},[],[780],{"type":25,"value":781},"color_system",{"type":25,"value":783}," 是包含控制台颜色系统的字符串（见下文）。",{"type":19,"tag":27,"props":785,"children":786},{"start":142},[787],{"type":19,"tag":31,"props":788,"children":789},{},[790,792,802,804,809],{"type":25,"value":791},"有几个“标准”用于将颜色写入终端，但并非全部都被普遍支持。Rich 会自动检测合适的颜色系统，或者你可以通过给",{"type":19,"tag":793,"props":794,"children":799},"a",{"href":795,"rel":796,"title":798},"https:\u002F\u002Frich.readthedocs.io\u002Fen\u002Fstable\u002Freference\u002Fconsole.html#rich.console.Console",[797],"nofollow","rich.console.Console",[800],{"type":25,"value":801},"构造器提供一个值",{"type":25,"value":803},"来手动设置。",{"type":19,"tag":44,"props":805,"children":807},{"className":806},[],[808],{"type":25,"value":781},{"type":25,"value":810},"你可以设置为以下其中之一：",{"type":19,"tag":554,"props":812,"children":813},{},[814,825,836,847,858,869],{"type":19,"tag":31,"props":815,"children":816},{},[817,823],{"type":19,"tag":44,"props":818,"children":820},{"className":819},[],[821],{"type":25,"value":822},"None",{"type":25,"value":824},"完全禁用颜色。",{"type":19,"tag":31,"props":826,"children":827},{},[828,834],{"type":19,"tag":44,"props":829,"children":831},{"className":830},[],[832],{"type":25,"value":833},"\"auto\"",{"type":25,"value":835},"会自动检测颜色系统。",{"type":19,"tag":31,"props":837,"children":838},{},[839,845],{"type":19,"tag":44,"props":840,"children":842},{"className":841},[],[843],{"type":25,"value":844},"\"standard\"",{"type":25,"value":846},"可显示8种颜色，包含正常和明亮变化，共16种颜色。",{"type":19,"tag":31,"props":848,"children":849},{},[850,856],{"type":19,"tag":44,"props":851,"children":853},{"className":852},[],[854],{"type":25,"value":855},"\"256\"",{"type":25,"value":857},"可以显示“标准”中的16种颜色，加上固定的240色调色板。",{"type":19,"tag":31,"props":859,"children":860},{},[861,867],{"type":19,"tag":44,"props":862,"children":864},{"className":863},[],[865],{"type":25,"value":866},"\"truecolor\"",{"type":25,"value":868},"可以显示1670万种颜色，这很可能就是你显示器能显示的所有颜色。",{"type":19,"tag":31,"props":870,"children":871},{},[872,878],{"type":19,"tag":44,"props":873,"children":875},{"className":874},[],[876],{"type":25,"value":877},"\"windows\"",{"type":25,"value":879},"在旧版Windows终端中可以显示8种颜色。新的Windows终端可以显示“真彩色”。",{"type":19,"tag":881,"props":882,"children":883},"blockquote",{},[884],{"type":19,"tag":77,"props":885,"children":886},{},[887,892],{"type":19,"tag":477,"props":888,"children":889},{},[890],{"type":25,"value":891},"Warning:",{"type":25,"value":893}," 警告\n设置颜色系统时要小心，如果你设置的颜色系统比终端支持的更高，文字可能会无法阅读。",{"type":19,"tag":27,"props":895,"children":896},{"start":151},[897],{"type":19,"tag":31,"props":898,"children":899},{},[900,906],{"type":19,"tag":44,"props":901,"children":903},{"className":902},[],[904],{"type":25,"value":905},"console.print()",{"type":25,"value":907}," 主要参数：",{"type":19,"tag":77,"props":909,"children":910},{},[911],{"type":19,"tag":477,"props":912,"children":913},{},[914],{"type":25,"value":915},"1. 样式相关",{"type":19,"tag":37,"props":917,"children":919},{"className":39,"code":918,"language":41,"meta":7,"style":7},"# 基础\nstyle=\"bold italic\"           # 粗体+斜体\nstyle=\"underline2\"           # 双下划线\nstyle=\"strike\"              # 删除线\nstyle=\"reverse\"             # 反色（前景\u002F背景互换）\nstyle=\"blink\"               # 闪烁\n\n# 颜色\nstyle=\"red on white\"        # 红字白底\nstyle=\"#ff00ff on #00ff00\" # RGB颜色\n\n# 渐变（仅限前景色）\nstyle=\"gradient(red,blue)\"  # 红到蓝渐变\n",[920],{"type":19,"tag":44,"props":921,"children":922},{"__ignoreMap":7},[923,931,939,947,955,963,971,980,988,996,1004,1011,1019],{"type":19,"tag":48,"props":924,"children":925},{"class":50,"line":51},[926],{"type":19,"tag":48,"props":927,"children":928},{},[929],{"type":25,"value":930},"# 基础\n",{"type":19,"tag":48,"props":932,"children":933},{"class":50,"line":60},[934],{"type":19,"tag":48,"props":935,"children":936},{},[937],{"type":25,"value":938},"style=\"bold italic\"           # 粗体+斜体\n",{"type":19,"tag":48,"props":940,"children":941},{"class":50,"line":69},[942],{"type":19,"tag":48,"props":943,"children":944},{},[945],{"type":25,"value":946},"style=\"underline2\"           # 双下划线\n",{"type":19,"tag":48,"props":948,"children":949},{"class":50,"line":142},[950],{"type":19,"tag":48,"props":951,"children":952},{},[953],{"type":25,"value":954},"style=\"strike\"              # 删除线\n",{"type":19,"tag":48,"props":956,"children":957},{"class":50,"line":151},[958],{"type":19,"tag":48,"props":959,"children":960},{},[961],{"type":25,"value":962},"style=\"reverse\"             # 反色（前景\u002F背景互换）\n",{"type":19,"tag":48,"props":964,"children":965},{"class":50,"line":160},[966],{"type":19,"tag":48,"props":967,"children":968},{},[969],{"type":25,"value":970},"style=\"blink\"               # 闪烁\n",{"type":19,"tag":48,"props":972,"children":973},{"class":50,"line":169},[974],{"type":19,"tag":48,"props":975,"children":977},{"emptyLinePlaceholder":976},true,[978],{"type":25,"value":979},"\n",{"type":19,"tag":48,"props":981,"children":982},{"class":50,"line":253},[983],{"type":19,"tag":48,"props":984,"children":985},{},[986],{"type":25,"value":987},"# 颜色\n",{"type":19,"tag":48,"props":989,"children":990},{"class":50,"line":262},[991],{"type":19,"tag":48,"props":992,"children":993},{},[994],{"type":25,"value":995},"style=\"red on white\"        # 红字白底\n",{"type":19,"tag":48,"props":997,"children":998},{"class":50,"line":271},[999],{"type":19,"tag":48,"props":1000,"children":1001},{},[1002],{"type":25,"value":1003},"style=\"#ff00ff on #00ff00\" # RGB颜色\n",{"type":19,"tag":48,"props":1005,"children":1006},{"class":50,"line":279},[1007],{"type":19,"tag":48,"props":1008,"children":1009},{"emptyLinePlaceholder":976},[1010],{"type":25,"value":979},{"type":19,"tag":48,"props":1012,"children":1013},{"class":50,"line":288},[1014],{"type":19,"tag":48,"props":1015,"children":1016},{},[1017],{"type":25,"value":1018},"# 渐变（仅限前景色）\n",{"type":19,"tag":48,"props":1020,"children":1021},{"class":50,"line":297},[1022],{"type":19,"tag":48,"props":1023,"children":1024},{},[1025],{"type":25,"value":1026},"style=\"gradient(red,blue)\"  # 红到蓝渐变\n",{"type":19,"tag":77,"props":1028,"children":1029},{},[1030],{"type":19,"tag":477,"props":1031,"children":1032},{},[1033],{"type":25,"value":1034},"2. 标记语法（Markup）",{"type":19,"tag":37,"props":1036,"children":1038},{"className":39,"code":1037,"language":41,"meta":7,"style":7},"\"[bold red on yellow]文本[\u002F]\"\n\"[link https:\u002F\u002Fexample.com]可点击链接[\u002F]\"\n",[1039],{"type":19,"tag":44,"props":1040,"children":1041},{"__ignoreMap":7},[1042,1050],{"type":19,"tag":48,"props":1043,"children":1044},{"class":50,"line":51},[1045],{"type":19,"tag":48,"props":1046,"children":1047},{},[1048],{"type":25,"value":1049},"\"[bold red on yellow]文本[\u002F]\"\n",{"type":19,"tag":48,"props":1051,"children":1052},{"class":50,"line":60},[1053],{"type":19,"tag":48,"props":1054,"children":1055},{},[1056],{"type":25,"value":1057},"\"[link https:\u002F\u002Fexample.com]可点击链接[\u002F]\"\n",{"type":19,"tag":77,"props":1059,"children":1060},{},[1061],{"type":19,"tag":477,"props":1062,"children":1063},{},[1064],{"type":25,"value":1065},"3. 其他重要参数",{"type":19,"tag":37,"props":1067,"children":1069},{"className":39,"code":1068,"language":41,"meta":7,"style":7},"justify=\"left\u002Fcenter\u002Fright\"  # 对齐方式\noverflow=\"fold\u002Fellipsis\"     # 超长文本处理\nemoji=False                  # 禁用表情符号\n",[1070],{"type":19,"tag":44,"props":1071,"children":1072},{"__ignoreMap":7},[1073,1081,1089],{"type":19,"tag":48,"props":1074,"children":1075},{"class":50,"line":51},[1076],{"type":19,"tag":48,"props":1077,"children":1078},{},[1079],{"type":25,"value":1080},"justify=\"left\u002Fcenter\u002Fright\"  # 对齐方式\n",{"type":19,"tag":48,"props":1082,"children":1083},{"class":50,"line":60},[1084],{"type":19,"tag":48,"props":1085,"children":1086},{},[1087],{"type":25,"value":1088},"overflow=\"fold\u002Fellipsis\"     # 超长文本处理\n",{"type":19,"tag":48,"props":1090,"children":1091},{"class":50,"line":69},[1092],{"type":19,"tag":48,"props":1093,"children":1094},{},[1095],{"type":25,"value":1096},"emoji=False                  # 禁用表情符号\n",{"type":19,"tag":77,"props":1098,"children":1099},{},[1100],{"type":25,"value":1101},"示例：",{"type":19,"tag":37,"props":1103,"children":1105},{"className":39,"code":1104,"language":41,"meta":7,"style":7},"console.print([1,2,3])  \nconsole.print(locals())  \nconsole.print(\"[blue underline]Looks like a link\")  \nconsole.print(\"FOO\",style=\"blink\")  \nconsole.print(\"[link https:\u002F\u002Fexample.com]可点击链接[\u002F]\")  \nconsole.print(\"[bold red on yellow]文本[\u002F]\")  \nconsole.print(\"[bold red on yellow]文本[\u002F]\",justify=\"center\")\n",[1106],{"type":19,"tag":44,"props":1107,"children":1108},{"__ignoreMap":7},[1109,1117,1125,1133,1141,1149,1157],{"type":19,"tag":48,"props":1110,"children":1111},{"class":50,"line":51},[1112],{"type":19,"tag":48,"props":1113,"children":1114},{},[1115],{"type":25,"value":1116},"console.print([1,2,3])  \n",{"type":19,"tag":48,"props":1118,"children":1119},{"class":50,"line":60},[1120],{"type":19,"tag":48,"props":1121,"children":1122},{},[1123],{"type":25,"value":1124},"console.print(locals())  \n",{"type":19,"tag":48,"props":1126,"children":1127},{"class":50,"line":69},[1128],{"type":19,"tag":48,"props":1129,"children":1130},{},[1131],{"type":25,"value":1132},"console.print(\"[blue underline]Looks like a link\")  \n",{"type":19,"tag":48,"props":1134,"children":1135},{"class":50,"line":142},[1136],{"type":19,"tag":48,"props":1137,"children":1138},{},[1139],{"type":25,"value":1140},"console.print(\"FOO\",style=\"blink\")  \n",{"type":19,"tag":48,"props":1142,"children":1143},{"class":50,"line":151},[1144],{"type":19,"tag":48,"props":1145,"children":1146},{},[1147],{"type":25,"value":1148},"console.print(\"[link https:\u002F\u002Fexample.com]可点击链接[\u002F]\")  \n",{"type":19,"tag":48,"props":1150,"children":1151},{"class":50,"line":160},[1152],{"type":19,"tag":48,"props":1153,"children":1154},{},[1155],{"type":25,"value":1156},"console.print(\"[bold red on yellow]文本[\u002F]\")  \n",{"type":19,"tag":48,"props":1158,"children":1159},{"class":50,"line":169},[1160],{"type":19,"tag":48,"props":1161,"children":1162},{},[1163],{"type":25,"value":1164},"console.print(\"[bold red on yellow]文本[\u002F]\",justify=\"center\")\n",{"type":19,"tag":77,"props":1166,"children":1167},{},[1168],{"type":19,"tag":81,"props":1169,"children":1171},{"alt":7,"src":1170},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211140355003.png",[],{"type":19,"tag":27,"props":1173,"children":1174},{"start":160},[1175],{"type":19,"tag":31,"props":1176,"children":1177},{},[1178,1184,1186],{"type":19,"tag":44,"props":1179,"children":1181},{"className":1180},[],[1182],{"type":25,"value":1183},"console.log()",{"type":25,"value":1185}," 关键参数：",{"type":19,"tag":27,"props":1187,"children":1188},{},[1189,1200,1211,1222,1233,1244,1255,1266,1277,1288],{"type":19,"tag":31,"props":1190,"children":1191},{},[1192,1198],{"type":19,"tag":44,"props":1193,"children":1195},{"className":1194},[],[1196],{"type":25,"value":1197},"*objects",{"type":25,"value":1199}," - 要打印的内容",{"type":19,"tag":31,"props":1201,"children":1202},{},[1203,1209],{"type":19,"tag":44,"props":1204,"children":1206},{"className":1205},[],[1207],{"type":25,"value":1208},"sep",{"type":25,"value":1210}," - 分隔符，默认空格",{"type":19,"tag":31,"props":1212,"children":1213},{},[1214,1220],{"type":19,"tag":44,"props":1215,"children":1217},{"className":1216},[],[1218],{"type":25,"value":1219},"end",{"type":25,"value":1221}," - 结尾符，默认换行",{"type":19,"tag":31,"props":1223,"children":1224},{},[1225,1231],{"type":19,"tag":44,"props":1226,"children":1228},{"className":1227},[],[1229],{"type":25,"value":1230},"style",{"type":25,"value":1232}," - 样式",{"type":19,"tag":31,"props":1234,"children":1235},{},[1236,1242],{"type":19,"tag":44,"props":1237,"children":1239},{"className":1238},[],[1240],{"type":25,"value":1241},"justify",{"type":25,"value":1243}," - 对齐方式",{"type":19,"tag":31,"props":1245,"children":1246},{},[1247,1253],{"type":19,"tag":44,"props":1248,"children":1250},{"className":1249},[],[1251],{"type":25,"value":1252},"emoji",{"type":25,"value":1254}," - 是否启用表情符号",{"type":19,"tag":31,"props":1256,"children":1257},{},[1258,1264],{"type":19,"tag":44,"props":1259,"children":1261},{"className":1260},[],[1262],{"type":25,"value":1263},"markup",{"type":25,"value":1265}," - 是否启用标记语法",{"type":19,"tag":31,"props":1267,"children":1268},{},[1269,1275],{"type":19,"tag":44,"props":1270,"children":1272},{"className":1271},[],[1273],{"type":25,"value":1274},"highlight",{"type":25,"value":1276}," - 是否启用自动高亮",{"type":19,"tag":31,"props":1278,"children":1279},{},[1280,1286],{"type":19,"tag":44,"props":1281,"children":1283},{"className":1282},[],[1284],{"type":25,"value":1285},"log_locals",{"type":25,"value":1287}," - 是否打印局部变量",{"type":19,"tag":31,"props":1289,"children":1290},{},[1291,1297],{"type":19,"tag":44,"props":1292,"children":1294},{"className":1293},[],[1295],{"type":25,"value":1296},"_stack_offset",{"type":25,"value":1298}," - 调用栈偏移量",{"type":19,"tag":77,"props":1300,"children":1301},{},[1302],{"type":25,"value":1101},{"type":19,"tag":37,"props":1304,"children":1306},{"className":39,"code":1305,"language":41,"meta":7,"style":7},"def func(msg=\"未查询到任何消息\", flag=False):  \n    a,b = 10,20  \n    console.log(\"[blue underline]Looks like a link\",log_locals=flag)  \n    time.sleep(1)  \n    console.log(f\"[bold red]ERROR消息[\u002F]: {msg}\")  \n    time.sleep(1)  \n    console.log(f\"[yellow]WARNING消息[\u002F]: {msg}\")  \n    time.sleep(1)  \n  \nprint(\"log_locals参数值为False效果展示\")  \nfunc()  \n  \nprint(\"log_locals参数值为True效果展示\")  \nfunc(flag=True)\n",[1307],{"type":19,"tag":44,"props":1308,"children":1309},{"__ignoreMap":7},[1310,1318,1326,1334,1342,1350,1357,1365,1372,1379,1387,1395,1402,1410],{"type":19,"tag":48,"props":1311,"children":1312},{"class":50,"line":51},[1313],{"type":19,"tag":48,"props":1314,"children":1315},{},[1316],{"type":25,"value":1317},"def func(msg=\"未查询到任何消息\", flag=False):  \n",{"type":19,"tag":48,"props":1319,"children":1320},{"class":50,"line":60},[1321],{"type":19,"tag":48,"props":1322,"children":1323},{},[1324],{"type":25,"value":1325},"    a,b = 10,20  \n",{"type":19,"tag":48,"props":1327,"children":1328},{"class":50,"line":69},[1329],{"type":19,"tag":48,"props":1330,"children":1331},{},[1332],{"type":25,"value":1333},"    console.log(\"[blue underline]Looks like a link\",log_locals=flag)  \n",{"type":19,"tag":48,"props":1335,"children":1336},{"class":50,"line":142},[1337],{"type":19,"tag":48,"props":1338,"children":1339},{},[1340],{"type":25,"value":1341},"    time.sleep(1)  \n",{"type":19,"tag":48,"props":1343,"children":1344},{"class":50,"line":151},[1345],{"type":19,"tag":48,"props":1346,"children":1347},{},[1348],{"type":25,"value":1349},"    console.log(f\"[bold red]ERROR消息[\u002F]: {msg}\")  \n",{"type":19,"tag":48,"props":1351,"children":1352},{"class":50,"line":160},[1353],{"type":19,"tag":48,"props":1354,"children":1355},{},[1356],{"type":25,"value":1341},{"type":19,"tag":48,"props":1358,"children":1359},{"class":50,"line":169},[1360],{"type":19,"tag":48,"props":1361,"children":1362},{},[1363],{"type":25,"value":1364},"    console.log(f\"[yellow]WARNING消息[\u002F]: {msg}\")  \n",{"type":19,"tag":48,"props":1366,"children":1367},{"class":50,"line":253},[1368],{"type":19,"tag":48,"props":1369,"children":1370},{},[1371],{"type":25,"value":1341},{"type":19,"tag":48,"props":1373,"children":1374},{"class":50,"line":262},[1375],{"type":19,"tag":48,"props":1376,"children":1377},{},[1378],{"type":25,"value":148},{"type":19,"tag":48,"props":1380,"children":1381},{"class":50,"line":271},[1382],{"type":19,"tag":48,"props":1383,"children":1384},{},[1385],{"type":25,"value":1386},"print(\"log_locals参数值为False效果展示\")  \n",{"type":19,"tag":48,"props":1388,"children":1389},{"class":50,"line":279},[1390],{"type":19,"tag":48,"props":1391,"children":1392},{},[1393],{"type":25,"value":1394},"func()  \n",{"type":19,"tag":48,"props":1396,"children":1397},{"class":50,"line":288},[1398],{"type":19,"tag":48,"props":1399,"children":1400},{},[1401],{"type":25,"value":148},{"type":19,"tag":48,"props":1403,"children":1404},{"class":50,"line":297},[1405],{"type":19,"tag":48,"props":1406,"children":1407},{},[1408],{"type":25,"value":1409},"print(\"log_locals参数值为True效果展示\")  \n",{"type":19,"tag":48,"props":1411,"children":1412},{"class":50,"line":306},[1413],{"type":19,"tag":48,"props":1414,"children":1415},{},[1416],{"type":25,"value":1417},"func(flag=True)\n",{"type":19,"tag":77,"props":1419,"children":1420},{},[1421],{"type":19,"tag":81,"props":1422,"children":1424},{"alt":7,"src":1423},"\u002Fimages\u002Fblog\u002Fpython-rich\u002Ffile-20260211143110202.png",[],{"type":19,"tag":27,"props":1426,"children":1427},{"start":169},[1428],{"type":19,"tag":31,"props":1429,"children":1430},{},[1431,1433,1439],{"type":25,"value":1432},"该",{"type":19,"tag":44,"props":1434,"children":1436},{"className":1435},[],[1437],{"type":25,"value":1438},"print_json",{"type":25,"value":1440},"方法可以很好地打印（格式化和样式）包含 JSON 的字符串。这里有一个简短的例子：",{"type":19,"tag":37,"props":1442,"children":1444},{"className":39,"code":1443,"language":41,"meta":7,"style":7},"console.print_json('[false, true, null, \"foo\"]')\n",[1445],{"type":19,"tag":44,"props":1446,"children":1447},{"__ignoreMap":7},[1448],{"type":19,"tag":48,"props":1449,"children":1450},{"class":50,"line":51},[1451],{"type":19,"tag":48,"props":1452,"children":1453},{},[1454],{"type":25,"value":1443},{"type":19,"tag":77,"props":1456,"children":1457},{},[1458],{"type":25,"value":1459},"你也可以通过记录一个对象来记录json:",{"type":19,"tag":37,"props":1461,"children":1463},{"className":39,"code":1462,"language":41,"meta":7,"style":7},"from rich.json import JSON\nconsole.log(JSON('[\"foo\", \"bar\"]'))\n",[1464],{"type":19,"tag":44,"props":1465,"children":1466},{"__ignoreMap":7},[1467,1475],{"type":19,"tag":48,"props":1468,"children":1469},{"class":50,"line":51},[1470],{"type":19,"tag":48,"props":1471,"children":1472},{},[1473],{"type":25,"value":1474},"from rich.json import JSON\n",{"type":19,"tag":48,"props":1476,"children":1477},{"class":50,"line":60},[1478],{"type":19,"tag":48,"props":1479,"children":1480},{},[1481],{"type":25,"value":1482},"console.log(JSON('[\"foo\", \"bar\"]'))\n",{"type":19,"tag":77,"props":1484,"children":1485},{},[1486,1488],{"type":25,"value":1487},"由于打印 JSON 是常见要求，你可以从主命名空间导入：",{"type":19,"tag":44,"props":1489,"children":1491},{"className":1490},[],[1492],{"type":25,"value":1438},{"type":19,"tag":37,"props":1494,"children":1496},{"className":39,"code":1495,"language":41,"meta":7,"style":7},"from rich import print_json\n",[1497],{"type":19,"tag":44,"props":1498,"children":1499},{"__ignoreMap":7},[1500],{"type":19,"tag":48,"props":1501,"children":1502},{"class":50,"line":51},[1503],{"type":19,"tag":48,"props":1504,"children":1505},{},[1506],{"type":25,"value":1495},{"type":19,"tag":77,"props":1508,"children":1509},{},[1510],{"type":25,"value":1511},"你也可以通过命令行漂亮地打印JSON，具体作如下：",{"type":19,"tag":37,"props":1513,"children":1517},{"className":1514,"code":1515,"language":1516,"meta":7,"style":7},"language-bash shiki shiki-themes github-dark","python -m rich.json cats.json\n","bash",[1518],{"type":19,"tag":44,"props":1519,"children":1520},{"__ignoreMap":7},[1521],{"type":19,"tag":48,"props":1522,"children":1523},{"class":50,"line":51},[1524,1529,1535,1541],{"type":19,"tag":48,"props":1525,"children":1527},{"style":1526},"--shiki-default:#B392F0",[1528],{"type":25,"value":41},{"type":19,"tag":48,"props":1530,"children":1532},{"style":1531},"--shiki-default:#79B8FF",[1533],{"type":25,"value":1534}," -m",{"type":19,"tag":48,"props":1536,"children":1538},{"style":1537},"--shiki-default:#9ECBFF",[1539],{"type":25,"value":1540}," rich.json",{"type":19,"tag":48,"props":1542,"children":1543},{"style":1537},[1544],{"type":25,"value":1545}," cats.json\n",{"type":19,"tag":77,"props":1547,"children":1548},{},[1549],{"type":25,"value":1101},{"type":19,"tag":37,"props":1551,"children":1553},{"className":39,"code":1552,"language":41,"meta":7,"style":7},"with open(\"灾难.json\",\"r\",encoding=\"utf-8\") as f:  \n    data = f.read()  \n  \n    # 方法一：直接调用print_json方法  \n    console.print_json(data)  \n  \n    # 方法二：实用JSON转化再调用log方法  \n    from rich.json import JSON  \n    console.log(JSON(data))\n",[1554],{"type":19,"tag":44,"props":1555,"children":1556},{"__ignoreMap":7},[1557,1565,1573,1580,1588,1596,1603,1611,1619],{"type":19,"tag":48,"props":1558,"children":1559},{"class":50,"line":51},[1560],{"type":19,"tag":48,"props":1561,"children":1562},{},[1563],{"type":25,"value":1564},"with open(\"灾难.json\",\"r\",encoding=\"utf-8\") as f:  \n",{"type":19,"tag":48,"props":1566,"children":1567},{"class":50,"line":60},[1568],{"type":19,"tag":48,"props":1569,"children":1570},{},[1571],{"type":25,"value":1572},"    data = f.read()  \n",{"type":19,"tag":48,"props":1574,"children":1575},{"class":50,"line":69},[1576],{"type":19,"tag":48,"props":1577,"children":1578},{},[1579],{"type":25,"value":148},{"type":19,"tag":48,"props":1581,"children":1582},{"class":50,"line":142},[1583],{"type":19,"tag":48,"props":1584,"children":1585},{},[1586],{"type":25,"value":1587},"    # 方法一：直接调用print_json方法  \n",{"type":19,"tag":48,"props":1589,"children":1590},{"class":50,"line":151},[1591],{"type":19,"tag":48,"props":1592,"children":1593},{},[1594],{"type":25,"value":1595},"    console.print_json(data)  \n",{"type":19,"tag":48,"props":1597,"children":1598},{"class":50,"line":160},[1599],{"type":19,"tag":48,"props":1600,"children":1601},{},[1602],{"type":25,"value":148},{"type":19,"tag":48,"props":1604,"children":1605},{"class":50,"line":169},[1606],{"type":19,"tag":48,"props":1607,"children":1608},{},[1609],{"type":25,"value":1610},"    # 方法二：实用JSON转化再调用log方法  \n",{"type":19,"tag":48,"props":1612,"children":1613},{"class":50,"line":253},[1614],{"type":19,"tag":48,"props":1615,"children":1616},{},[1617],{"type":25,"value":1618},"    from rich.json import JSON  \n",{"type":19,"tag":48,"props":1620,"children":1621},{"class":50,"line":262},[1622],{"type":19,"tag":48,"props":1623,"children":1624},{},[1625],{"type":25,"value":1626},"    console.log(JSON(data))\n",{"type":19,"tag":1230,"props":1628,"children":1629},{},[1630],{"type":25,"value":1631},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":60,"depth":60,"links":1633},[1634,1635],{"id":22,"depth":69,"text":22},{"id":664,"depth":69,"text":667},"markdown","content:blog:2026-02-11-python-rich.md","content","blog\u002F2026-02-11-python-rich.md","blog\u002F2026-02-11-python-rich","md",1780801017878]