【问题标题】:Some numbers are automatically formatted using rich.console, how to prevent this?使用rich.console 会自动格式化一些数字,如何防止这种情况发生?
【发布时间】:2021-07-23 13:44:54
【问题描述】:

以下代码

from rich.console import Console

console = Console()

console.print("ciao-16S-123")

将打印突出显示的数字 123(在我的终端中以蓝色显示)。 这发生在许多带有数字的字符串上,可能是什么问题 导致这种不需要的格式,以及如何防止它?

【问题讨论】:

    标签: python rich


    【解决方案1】:

    根据Richdocumentation“Rich 可以将样式应用于您 print() 或 log() 的文本模式。使用默认设置,Rich 将突出显示数字、字符串、集合等内容、布尔值、None 以及一些更奇特的模式,例如文件路径、URL 和 UUID。”

    你可以这样禁用它:

    console.print("ciao-16S-123", highlight=False)
    

    您还可以定义更适合您需求的custom highlighter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-09
      • 2023-04-02
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多