current position:Home>Pythonnote032 --- Python print colored string
Pythonnote032 --- Python print colored string
2022-07-25 15:08:27【Weigtang 406 team】
Intro
There is a lot of information on the Internet , Not much to say , There are other ways . Record the small functions encapsulated by yourself , Convenient for your own use .
Code
def magic_str(raw_str, display_mode="", font_color="", back_color=""):
""" jupyter Color can be displayed when printing :param raw_str: Original string :param display_mode:0 Default 1 bold 4 Underline 5 flashing 7 On the contrary :param font_color: Font color -30 black 31 red 32 green 33 yellow 34 blue 35 purple 36 green 37 white :param back_color: Background color -40 black 41 red 42 green 43 yellow 44 blue 45 purple 46 green 47 white :return: """
display_str = "" if display_mode == "" else display_mode + ";"
font_str = "" if font_color == "" else font_color + ";"
back_str = "" if back_color == "" else back_color + ";"
str_mode = display_str + font_str + back_str
str_mode = str_mode[0:-1]
res = '\033[' + str_mode + "m" + raw_str + " \033[0m"
return res
print(magic_str("test",display_mode="1",font_color='31')+" test")
Ref
[1] https://stackoverflow.com/questions/287871/how-to-print-colored-text-to-the-terminal
2021-09-14 Jiulong lake, Jiangning District, Nanjing
copyright notice
author[Weigtang 406 team],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/206/202207251501086412.html
The sidebar is recommended
- Python Xiaobai foundation -- tuple
- Python Xiaobai foundation -- dictionary Dict
- Python solve the problem of slow download and installation of Pip
- pandas.date_ range
- what the fuck! This is the best Python technology realization scheme!
- [version 2022] super detailed python+pychar installation nanny level tutorial, python environment configuration and use guide. It's enough to read this article
- At the age of 26, switching to Python is the most successful thing in my life
- How to write simple Trojan horse program with Python
- Python realizes video information acquisition
- [SSTI module injection] ssti+flask+python (Part 1): basic knowledge
guess what you like
[SSTI module injection] ssti+flask+python (middle): vulnerability exploitation
[SSTI module injection] ssti+flask+python (bottom): bypass filtering
leetcode 34. Find First and Last Position of Element in Sorted Array(python)
Implementing greedy algorithm in Python
[Python] QT code realizes clicking the button page to jump back and forth
[Python] convolutional neural network
[Python] baiduai face detection, face search, face registration
pandas
From Chinese, python font anti crawling practical cases, and one more point
Python collection
Random recommended
- Python decorator
- Python simple test
- Python requests module
- How to write the formula y=a*exp (b*x) as a condition in python (parameter estimation program using least square fitting)
- Python modulenotfounderror: no module named '* * *' solution
- Numpy of Python learning
- Python Wu Enda deep learning assignment 17 -- deep learning and art neurostyle transfer (NST)
- Python output font color
- Pandas modify column
- leetcode 240. Search a 2D Matrix II(python)
- How does Django realize remote file download?
- How does Python count the number of lines?
- Python uses ARIMA and arimax to predict the time series data of store commodity sales demand
- Python reads all the pictures in the folder and writes the picture names line by line into TXT
- Django3 ----- views and simple templates
- Web development Python
- Django 2 ----- database and admin
- Django 1 ----- installation and start-up
- What is the reason why Python socket client reports an error connection reset by peer?
- Detailed explanation of static method usage in Python
- Python_ Simulate login to QQ email & save cookies
- Python_ Crawl_ Spider crawls the recruitment network
- Python pit entry Guide
- Vscode Python code completion repetition
- Python decorator with parameters
- Python list deep copy shallow copy
- Django+vue quickly realizes blog website
- Python data analysis and machine learning 27 examples of spelling correction
- Python data analysis and machine learning 28 news classification
- After reading so many Python tutorials, the most delicious thing is
- Several ways for Python to write xlsx files
- Summary of Python object-oriented details
- Python multi process / process pool / shared data between processes practical scenario analysis and practice pit records
- How to import sort into pandas foundation?
- What are columns in pandas foundation?
- Why not use apply in pandas foundation?
- Python decorator engineering examples and key points summary
- Triplicate in Python
- Implementation, encapsulation and call of paging function in Django (super detailed)
- Learning pandas, you can't stop at all