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

1

11

The following code

from rich.console import Console

console = Console()

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

will print the number 123 highlighted (in blue, in my terminal). This happens on many strings with numbers, what could be the problem that causes this unwanted formatting, and how to prevent it?

enter image description here

Martini answered 23/7, 2021 at 13:44 Comment(0)
C
12

As per Rich documentation, "Rich can apply styles to patterns in text which you print() or log(). With the default settings, Rich will highlight things such as numbers, strings, collections, booleans, None, and a few more exotic patterns such as file paths, URLs and UUIDs."

You can disable it like this:

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

You can also define a custom highlighter better suited for your needs.

Circlet answered 24/7, 2021 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.