pypi.org/project/ter…python
不少開發的小夥伴都知道在利用 Python 在 Console 界面輸出顏色內容, 可是今天要介紹的是另外一種方式:shell
python -m pip install termcolor
複製代碼
你能夠直接這樣使用它:spa
#!/usr/bin/env python
# _*_ Coding: UTF-8 _*_
from termcolor import cprint
cprint('color', 'red', attrs=['reverse', 'blink'])
複製代碼
你在 Pycharm 獲得的結果就是: 3d
Medusa.py
中, 使用如下方式執行, 那麼你的設置可能有效:
python3 Medusa.py
複製代碼
你能夠自由配置你須要附加的屬性:code
在上述截圖中是否是參數沒有獲得生效呢?cdn
#!/usr/bin/env python
# _*_ Coding: UTF-8 _*_
from termcolor import cprint
cprint('color', 'green')
cprint('Medusa', color='red', on_color='on_yellow')
cprint('Sorcerer', attrs=['underline'])
複製代碼