Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

python - Can't reset colours after RICH formatting

I have a problem with the rich library. After installing it, I wrote in the code:

from rich import print

d = {
    "employee1": "telephone: 123-456-789 -",
    "employee2": "telephone: 098-654-321",
}
# and in the line with the code I set the color magenta bold:
print(
    d.get(p, "[bold magenta] there is no such employee [/ bold magenta]!")
)

The problem is following. After the first attempt to change the color, the color of the text "there is no such employee" wasn't changed but the color of the telephone number changed. Then I removed the color formatting line, but still the phone number has magenta color.

Now, if change the text "there is no such employee" to red color, it change but the phone number is still in magenta.

Even when i remove text formatting and leave only from rich import print i still got the phone number in magenta.

question from:https://stackoverflow.com/questions/65915637/cant-reset-colours-after-rich-formatting

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like it's a default setting. Have a look at https://rich.readthedocs.io/en/latest/highlighting.html .

To quote from the top of that page:

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 highlighting either by setting highlight=False on print() or log(), or by setting highlight=False on the Console constructor which disables it everywhere.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...