一些数字使用 rich.console 自动格式化,如何防止这种情况?

Some numbers are automatically formatted using rich.console, how to prevent this?

代码如下

from rich.console import Console

console = Console()

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

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

As per Rich documentation, "Rich 可以将样式应用于您打印() 或 log() 的文本中的模式。使用默认设置,Rich 将突出显示例如数字、字符串、集合、布尔值、None,以及一些更奇特的模式,例如文件路径、URL 和 UUID。"

您可以这样禁用它:

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

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